dell wyse 5070 安装了ubuntu 25.10 做一台铃声服务器

younghuie3周前 (11-12)ubuntu相关21

首先要解决让它有声音呢。警察好像声卡是Realtek ALC3253。

sudo apt update
sudo apt install alsa-utils mpg123 ffmpeg

ffmpeg不必须,我用mpg123挺好的。

lsmod | grep snd
lspci -nnk | grep -A3 -i audio
dmesg | grep -i snd | tail -n 50

以上用于查看内核识别的声卡与模块

aplay -l
arecord -l
cat /proc/asound/cards

ALSA 设备列表与测试播放设备

如果 aplay -l 没设备 → 检查 BIOS(Onboard Audio Enabled)或硬件连接/驱动。若列出卡和设备,记下 card# 与 device#(例如 card 0 device 0)。


alsamixer

调节音量用。

speaker-test -D plughw:0,0 -c 2 -t wav

播放看看呢。


如果还不行:

lspci -nnk | grep -A3 -i audio

应该会看到以下输出:

00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio
	Subsystem: Dell Device ...
	Kernel driver in use: snd_hda_intel

如果还没有看到加载snd_hda_intel:

就这么操作:

sudo modprobe snd_hda_intel
dmesg | grep -i hda


以下查看声卡设备:

aplay -l

以下还是调节音量

alsamixer

master一定不要静音。


测试播放:

speaker-test -D plughw:0,0 -c 2 -t wav


忘了说了,第一次如果失败,切记一定要reboot一下,我就这么浪费了很久时间。


用chatgpt写了一个bash,稍微修改一下:

#!/bin/bash

# ========== Auto School Bell System ==========

# Depend: sudo apt install mpg123



RING_DIR="$(cd "$(dirname "$0")" && pwd)"

LOG_FILE="$RING_DIR/bell_log.txt"



clear
echo
echo "made by younghuie.TEL:13371896527"
echo "-----------------------------------------------------"

echo "     🔔 Auto School Bell System (2025.11.11)"

echo "-----------------------------------------------------"
echo
echo "Here's Some Available schedule files:"
echo
ls "$RING_DIR"/schedule_*.txt 2>/dev/null || echo "(no preset found)"
echo
echo
read -p "Enter schedule filename (e.g. schedule_class.txt): " SCHEME

SCHEDULE_FILE="$RING_DIR/$SCHEME"



if [ ! -f "$SCHEDULE_FILE" ]; then

  echo "❌ File not found: $SCHEDULE_FILE"

  exit 1

fi



declare -A played

today=$(date +%F)



echo

echo "✅ Current schedule: $SCHEME"
echo "📅 Date: $today"

sleep 2



get_next_time() {

  local now

  now=$(date +%s)

  while IFS=' ' read -r t e; do

    [[ -z "$t" ]] && continue

    event_time=$(date -d "$today $t" +%s)

    if (( event_time > now )); then

      echo "$t $e"

      return

    fi

  done < "$SCHEDULE_FILE"

}



while true; do

  clear
  echo
  echo "🔔 Current schedule: $SCHEME"
  echo
  echo "⏰ Current time: $(date '+%H:%M:%S')"

  echo "-----------------------------------------------------"

  echo " PLANNED.TIME                STATUS"

  echo "-----------------------------------------------------"



  now_sec=$(date +%s)

  while IFS=' ' read -r time event; do

    [[ -z "$time" ]] && continue

    event_sec=$(date -d "$today $time" +%s)



    if (( now_sec > event_sec )) && [[ "${played[$time]}" != "yes" ]]; then

      played[$time]="skipped"

      echo "|  $time      |       ❌ missed ($event)"

    elif (( now_sec == event_sec )) && [[ "${played[$time]}" != "yes" ]]; then

      played[$time]="yes"

      echo "|  $time      |       🔊 playing ($event)"

      nohup mpg123 -q "$RING_DIR/$event.mp3" >/dev/null 2>&1 &

      echo "$(date '+%F %T') played $event.mp3" >> "$LOG_FILE"

    elif [[ "${played[$time]}" == "yes" ]]; then

      echo "|  $time      |       ✅ played ($event)"

    elif [[ "${played[$time]}" == "skipped" ]]; then

      echo "|  $time      |       ❌ missed ($event)"

    else

      echo "|  $time      |       ⏳ pending ($event)"

    fi

  done < "$SCHEDULE_FILE"


   echo "-----------------------------------------------------"

  next_info=$(get_next_time)

  if [[ -n "$next_info" ]]; then

    next_time=$(echo "$next_info" | awk '{print $1}')

    next_event=$(echo "$next_info" | awk '{print $2}')

    target_sec=$(date -d "$today $next_time" +%s)

    diff=$((target_sec - now_sec))
    
    echo "Next bell: "$next_event.mp3" at $next_time"
    echo
    echo "Current Time: $(date '+%H:%M:%S') | Countdown: $diff seconds"

  else

    echo "All bells finished for today."

  fi



  echo "-----------------------------------------------------"

  echo "Press Ctrl+C to exit."

  sleep 0.5



  # Reset at midnight

  if [[ "$(date +%F)" != "$today" ]]; then

    today=$(date +%F)

    played=()

    echo "------------- New day, status reset -------------"

  fi

done


具体文件结构如下:

ring/
 ├── bell.sh
 ├── begin.mp3
 ├── over.mp3
 ├── schedule_class.txt
 └── bell_log.txt

实测还是比较完美的,整机功耗待机在5w以内,哈哈。


另有windows的bat版,记得好几年前整过一回,总体感觉跟这个bash都不是特别好的方案,因为采用当前时间来对比设置时间的,比中后就运行,如果sleep设置太大会错过铃声,设置太小,刷新太快会增加cpu负担,或者屏幕刷新太快,眼睛受不了,实测设置为1的时候,真的会错过铃声播放的,经过调整,设置为0.5的时候,基本没问题,可同时修改播放列表txt文件,而不必关闭当前这个shell。


另外如果ssh连接或者跑到服务器前,ctrl+C的方式,很容易误触。建议用screen来解决这个问题。代码如下,如果没安装过的先装一下。

screen -S ring #取个名字,然后进去后就行了,退出时候用:
ctrl+A+D

查看开了几个screen:

screen -ls

进入某一个screen:

screen -r ring #这里以ring为例


分享给朋友:
返回列表

上一篇:原版的ubutntu_ip修改的netplan配置如下

没有最新的文章了...