fix: 修复自启动脚本

This commit is contained in:
Del Wang
2025-05-11 19:13:21 +08:00
parent 6bdd1b9683
commit e687280ab1
5 changed files with 143 additions and 17 deletions
+7 -4
View File
@@ -24,15 +24,18 @@ cat <<EOF > /data/open-xiaoai/kws/reply.txt
主人你好,请问有什么吩咐?
EOF
# 运行启动脚本
# 运行启动脚本 init.sh
curl -sSfL https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-kws/init.sh | sh
```
如果你想要开机自启动,可以运行以下命令,然后重启小爱音箱即可。
如果你想要开机自启动,运行以下命令重启小爱音箱即可。
```shell
# 下载到 /data/init.sh 开机时自启动
curl -L -o /data/init.sh https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-kws/init.sh
# 下载 boot.sh 到 /data/init.sh 开机时自启动
curl -L -o /data/init.sh https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-kws/boot.sh
# 重启小爱音箱
reboot
```
## 设置唤醒词
+85
View File
@@ -0,0 +1,85 @@
#! /bin/sh
set -e
MIN_SPACE_MB=32
DOWNLOAD_BASE_URL="https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-kws"
check_disk_space() {
local space_kb=$(df -k "$1" | awk 'NR==2 {print $4}')
if [ $((space_kb / 1024)) -lt "$MIN_SPACE_MB" ]; then
echo 1
else
echo 0
fi
}
BASE_DIR="/data"
if [ $(check_disk_space "$BASE_DIR") -eq 1 ]; then
BASE_DIR="/tmp"
if [ $(check_disk_space "$BASE_DIR") -eq 1 ]; then
echo "❌ 磁盘空间不足,请先清理磁盘空间(至少需要 $MIN_SPACE_MB MB 空间)"
exit 1
fi
fi
WORK_DIR="$BASE_DIR/open-xiaoai/kws"
KWS_BIN="$WORK_DIR/kws"
if [ ! -d "$WORK_DIR" ]; then
mkdir -p "$WORK_DIR"
fi
if [ ! -f "$WORK_DIR/models/encoder.onnx" ]; then
echo "🔥 正在下载模型文件..."
curl -L -# -o "$WORK_DIR/kws.tar.gz" "$DOWNLOAD_BASE_URL/kws.tar.gz"
tar -xzvf "$WORK_DIR/kws.tar.gz" -C "$WORK_DIR"
chmod +x "$KWS_BIN"
rm "$WORK_DIR/kws.tar.gz"
echo "✅ 模型文件下载完毕"
fi
CONFIG_DIR="/data/open-xiaoai/kws"
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
fi
if [ ! -f "$CONFIG_DIR/keywords.txt" ]; then
echo "n ǐ h ǎo x iǎo zh ì @你好小智" >> "$CONFIG_DIR/keywords.txt"
echo "d òu b āo d òu b āo @豆包豆包" >> "$CONFIG_DIR/keywords.txt"
echo "t iān m āo j īng l íng @天猫精灵" >> "$CONFIG_DIR/keywords.txt"
echo "x iǎo d ù x iǎo d ù @小度小度" >> "$CONFIG_DIR/keywords.txt"
echo "✅ 默认唤醒词已创建"
fi
if [ "$1" != "--no-monitor" ]; then
# 如果没有设置 --no-monitor 参数,则启动 monitor 进程
MONITOR_BIN="$CONFIG_DIR/monitor"
if [ ! -f "$MONITOR_BIN" ]; then
curl -L -# -o "$MONITOR_BIN" "$DOWNLOAD_BASE_URL/monitor"
chmod +x "$MONITOR_BIN"
fi
kill -9 `ps|grep "open-xiaoai/kws/monitor"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$MONITOR_BIN" > /dev/null 2>&1 &
fi
echo "🔥 正在启动唤醒词识别服务,请耐心等待..."
echo "🐢 模型加载较慢,请在语音提示初始化成功后,再使用自定义唤醒词"
kill -9 `ps|grep "open-xiaoai/kws/kws"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$KWS_BIN" \
--model-type=zipformer2 \
--tokens="$WORK_DIR/models/tokens.txt" \
--encoder="$WORK_DIR/models/encoder.onnx" \
--decoder="$WORK_DIR/models/decoder.onnx" \
--joiner="$WORK_DIR/models/joiner.onnx" \
--keywords-file="/data/open-xiaoai/kws/keywords.txt" \
--provider=cpu \
--num-threads=1 \
--chunk-size=1024 \
noop
+11 -9
View File
@@ -44,17 +44,11 @@ fi
CONFIG_DIR="/data/open-xiaoai/kws"
MONITOR_BIN="$CONFIG_DIR/monitor"
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
fi
if [ ! -f "$MONITOR_BIN" ]; then
curl -L -# -o "$MONITOR_BIN" "$DOWNLOAD_BASE_URL/monitor"
chmod +x "$MONITOR_BIN"
fi
if [ ! -f "$CONFIG_DIR/keywords.txt" ]; then
echo "n ǐ h ǎo x iǎo zh ì @你好小智" >> "$CONFIG_DIR/keywords.txt"
echo "d òu b āo d òu b āo @豆包豆包" >> "$CONFIG_DIR/keywords.txt"
@@ -63,12 +57,20 @@ if [ ! -f "$CONFIG_DIR/keywords.txt" ]; then
echo "✅ 默认唤醒词已创建"
fi
if [ "$1" != "--no-monitor" ]; then
# 如果没有设置 --no-monitor 参数,则启动 monitor 进程
MONITOR_BIN="$CONFIG_DIR/monitor"
if [ ! -f "$MONITOR_BIN" ]; then
curl -L -# -o "$MONITOR_BIN" "$DOWNLOAD_BASE_URL/monitor"
chmod +x "$MONITOR_BIN"
fi
kill -9 `ps|grep "open-xiaoai/kws/monitor"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$MONITOR_BIN" &
fi
echo "🔥 正在启动唤醒词识别服务,请耐心等待..."
echo "🐢 模型加载较慢,请在语音提示初始化成功后,再使用自定义唤醒词"
kill -9 `ps|grep "open-xiaoai/kws/monitor"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$MONITOR_BIN" &
kill -9 `ps|grep "open-xiaoai/kws/kws"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$KWS_BIN" \
--model-type=zipformer2 \
+7 -4
View File
@@ -19,7 +19,7 @@ mkdir /data/open-xiaoai
# 设置 server 地址(注意替换成自己的 server 地址)
echo 'ws://192.168.31.227:4399' > /data/open-xiaoai/server.txt
# 运行启动脚本
# 运行启动脚本 init.sh
curl -sSfL https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-client/init.sh | sh
```
@@ -28,11 +28,14 @@ curl -sSfL https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-cli
>
> 注意安全!不要连接来路不明的 server 🚨
如果你想要开机自启动,可以运行以下命令,然后重启小爱音箱即可。
如果你想要开机自启动,运行以下命令重启小爱音箱即可。
```shell
# 下载到 /data/init.sh 开机时自启动
curl -L -o /data/init.sh https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-client/init.sh
# 下载 boot.sh 文件到 /data/init.sh 开机时自启动
curl -L -o /data/init.sh https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-client/boot.sh
# 重启小爱音箱
reboot
```
## 编译运行
+33
View File
@@ -0,0 +1,33 @@
#! /bin/sh
set -e
DOWNLOAD_BASE_URL="https://gitee.com/idootop/artifacts/releases/download/open-xiaoai-client"
WORK_DIR="/data/open-xiaoai"
CLIENT_BIN="$WORK_DIR/client"
SERVER_ADDRESS="ws://127.0.0.1:4399" # 默认不会连接到任何 server
if [ ! -d "$WORK_DIR" ]; then
mkdir -p "$WORK_DIR"
fi
if [ ! -f "$CLIENT_BIN" ]; then
echo "🔥 正在下载 Client 端补丁程序..."
curl -L -# -o "$CLIENT_BIN" "$DOWNLOAD_BASE_URL/client"
chmod +x "$CLIENT_BIN"
echo "✅ Client 端补丁程序下载完毕"
fi
if [ -f "$WORK_DIR/server.txt" ]; then
SERVER_ADDRESS=$(cat "$WORK_DIR/server.txt")
fi
echo "🔥 正在启动 Client 端补丁程序..."
kill -9 `ps|grep "open-xiaoai/client"|grep -v grep|awk '{print $1}'` > /dev/null 2>&1 || true
"$CLIENT_BIN" "$SERVER_ADDRESS" > /dev/null 2>&1