Merge pull request #105 from kslr/main

feat: 优化小智的音频与唤醒链路
This commit is contained in:
Del
2026-02-24 15:26:04 +08:00
committed by GitHub
4 changed files with 6 additions and 16 deletions
+3 -5
View File
@@ -136,15 +136,13 @@ APP_CONFIG = {
### Q:唤醒词一直没有反应? ### Q:唤醒词一直没有反应?
由于小爱音箱远场拾音音量较小,有时可能会识别不清,你可以调大 `config.py` 配置文件里的 `boost` 参数,然后重启应用 / Docker 试试看。 如果唤醒词还是不敏感,可以先调低 `vad.threshold`,然后重启应用 / Docker 试试看。
```py ```py
APP_CONFIG = { APP_CONFIG = {
"vad": { "vad": {
# 小爱音箱录音音量较小,需要后期放大一下 # 语音检测阈值(0-1,越小越灵敏)
"boost": 100, "threshold": 0.05,
# boost 调大后,语音检测阈值可能也需要一起调大些
"threshold": 0.50,
}, },
# ... 其他配置 # ... 其他配置
} }
-2
View File
@@ -53,8 +53,6 @@ APP_CONFIG = {
"after_wakeup": after_wakeup, "after_wakeup": after_wakeup,
}, },
"vad": { "vad": {
# 录音音量增强倍数(小爱音箱录音音量较小,需要后期放大一下)
"boost": 10,
# 语音检测阈值(0-1,越小越灵敏) # 语音检测阈值(0-1,越小越灵敏)
"threshold": 0.10, "threshold": 0.10,
# 最小语音时长(ms # 最小语音时长(ms
@@ -9,10 +9,10 @@ class _SherpaOnnx:
self.keyword_spotter = sherpa_onnx.KeywordSpotter( self.keyword_spotter = sherpa_onnx.KeywordSpotter(
provider="cpu", provider="cpu",
num_threads=1, num_threads=1,
max_active_paths=4, max_active_paths=8,
keywords_score=2.0, keywords_score=2.0,
keywords_threshold=0.2, keywords_threshold=0.2,
num_trailing_blanks=1, num_trailing_blanks=0,
keywords_file=get_model_file_path("keywords.txt"), keywords_file=get_model_file_path("keywords.txt"),
tokens=get_model_file_path("tokens.txt"), tokens=get_model_file_path("tokens.txt"),
encoder=get_model_file_path("encoder.onnx"), encoder=get_model_file_path("encoder.onnx"),
@@ -1,9 +1,6 @@
import uuid import uuid
from typing import Any, Callable, ClassVar, Optional from typing import Any, Callable, ClassVar, Optional
import numpy as np
from config import APP_CONFIG
from xiaozhi.ref import get_xiaoai from xiaozhi.ref import get_xiaoai
@@ -88,10 +85,7 @@ class MyStream:
return return
if len(data) > 0: if len(data) > 0:
samples = np.frombuffer(data, dtype=np.int16) self.input_bytes.extend(data)
# 小爱音箱录音音量较小,需要后期放大一下
samples = samples * APP_CONFIG["vad"]["boost"]
self.input_bytes.extend(samples.tobytes())
def read(self, num_frames=None, exception_on_overflow=False) -> bytes: def read(self, num_frames=None, exception_on_overflow=False) -> bytes:
if num_frames is None: if num_frames is None: