From e687280ab173bf36e93e87c49b686b0568b20f17 Mon Sep 17 00:00:00 2001 From: Del Wang Date: Sun, 11 May 2025 19:13:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/kws/README.md | 11 +++-- examples/kws/boot.sh | 85 ++++++++++++++++++++++++++++++++++ examples/kws/init.sh | 20 ++++---- packages/client-rust/README.md | 11 +++-- packages/client-rust/boot.sh | 33 +++++++++++++ 5 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 examples/kws/boot.sh create mode 100644 packages/client-rust/boot.sh diff --git a/examples/kws/README.md b/examples/kws/README.md index 4e7f77b..eb8175b 100644 --- a/examples/kws/README.md +++ b/examples/kws/README.md @@ -24,15 +24,18 @@ cat < /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 ``` ## 设置唤醒词 diff --git a/examples/kws/boot.sh b/examples/kws/boot.sh new file mode 100644 index 0000000..18bf3d6 --- /dev/null +++ b/examples/kws/boot.sh @@ -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 diff --git a/examples/kws/init.sh b/examples/kws/init.sh index 896370b..cff922e 100644 --- a/examples/kws/init.sh +++ b/examples/kws/init.sh @@ -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 \ diff --git a/packages/client-rust/README.md b/packages/client-rust/README.md index 71f21fa..e1e8d92 100644 --- a/packages/client-rust/README.md +++ b/packages/client-rust/README.md @@ -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 ``` ## 编译运行 diff --git a/packages/client-rust/boot.sh b/packages/client-rust/boot.sh new file mode 100644 index 0000000..6e38ae5 --- /dev/null +++ b/packages/client-rust/boot.sh @@ -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