mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 10:03:54 +08:00
fix: asr识别缺字现象,去除无用的变量
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import time
|
import time
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
from core.handle.sendAudioHandle import send_stt_message
|
from core.handle.sendAudioHandle import send_stt_message
|
||||||
from core.handle.intentHandler import handle_user_intent
|
from core.handle.intentHandler import handle_user_intent
|
||||||
@@ -14,14 +13,6 @@ TAG = __name__
|
|||||||
async def handleAudioMessage(conn, audio):
|
async def handleAudioMessage(conn, audio):
|
||||||
# 当前片段是否有人说话
|
# 当前片段是否有人说话
|
||||||
have_voice = conn.vad.is_vad(conn, audio)
|
have_voice = conn.vad.is_vad(conn, audio)
|
||||||
# 如果设备刚刚被唤醒,短暂忽略VAD检测
|
|
||||||
if have_voice and hasattr(conn, "just_woken_up") and conn.just_woken_up:
|
|
||||||
have_voice = False
|
|
||||||
# 设置一个短暂延迟后恢复VAD检测
|
|
||||||
conn.asr_audio.clear()
|
|
||||||
if not hasattr(conn, "vad_resume_task") or conn.vad_resume_task.done():
|
|
||||||
conn.vad_resume_task = asyncio.create_task(resume_vad_detection(conn))
|
|
||||||
return
|
|
||||||
|
|
||||||
if have_voice:
|
if have_voice:
|
||||||
if conn.client_is_speaking:
|
if conn.client_is_speaking:
|
||||||
@@ -31,13 +22,6 @@ async def handleAudioMessage(conn, audio):
|
|||||||
# 接收音频
|
# 接收音频
|
||||||
await conn.asr.receive_audio(conn, audio, have_voice)
|
await conn.asr.receive_audio(conn, audio, have_voice)
|
||||||
|
|
||||||
|
|
||||||
async def resume_vad_detection(conn):
|
|
||||||
# 等待2秒后恢复VAD检测
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
conn.just_woken_up = False
|
|
||||||
|
|
||||||
|
|
||||||
async def startToChat(conn, text):
|
async def startToChat(conn, text):
|
||||||
# 检查输入是否是JSON格式(包含说话人信息)
|
# 检查输入是否是JSON格式(包含说话人信息)
|
||||||
speaker_name = None
|
speaker_name = None
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import time
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from typing import Optional, Tuple, List, Dict, Any
|
from typing import Optional, Tuple, List
|
||||||
from core.handle.receiveAudioHandle import startToChat
|
from core.handle.receiveAudioHandle import startToChat
|
||||||
from core.handle.reportHandle import enqueue_asr_report
|
from core.handle.reportHandle import enqueue_asr_report
|
||||||
from core.utils.util import remove_punctuation_and_length
|
from core.utils.util import remove_punctuation_and_length
|
||||||
@@ -132,8 +132,6 @@ class ASRProviderBase(ABC):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# 使用线程池执行器并行运行
|
# 使用线程池执行器并行运行
|
||||||
parallel_start_time = time.monotonic()
|
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as thread_executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as thread_executor:
|
||||||
asr_future = thread_executor.submit(run_asr)
|
asr_future = thread_executor.submit(run_asr)
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class VADProvider(VADProviderBase):
|
|||||||
int(min_silence_duration_ms) if min_silence_duration_ms else 1000
|
int(min_silence_duration_ms) if min_silence_duration_ms else 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
# 至少要多少帧才算有语音
|
# 至少要多少帧才算有语音,增加灵敏度
|
||||||
self.frame_window_threshold = 3
|
self.frame_window_threshold = 1
|
||||||
|
|
||||||
def is_vad(self, conn, opus_packet):
|
def is_vad(self, conn, opus_packet):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user