Merge pull request #60 from Plaud-AI/feat/demo

feat: non-streaming ASR doesn't pass text length interruption strategy
This commit is contained in:
Harold-Guo 2025-12-21 13:57:21 +08:00 committed by GitHub
commit 04321383db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 28 deletions

View file

@ -1535,7 +1535,8 @@ class ConnectionHandler:
2. TTS must be speaking (client_is_speaking = True) 2. TTS must be speaking (client_is_speaking = True)
3. Not in manual listen mode 3. Not in manual listen mode
4. Speech duration >= min_interrupt_speech_duration_ms 4. Speech duration >= min_interrupt_speech_duration_ms
5. ASR text buffer length >= min_interrupt_text_length 5. For streaming ASR: text buffer length >= min_interrupt_text_length
For non-streaming ASR: skip text check (not available during speech)
Args: Args:
speech_duration_ms: Current speech duration in milliseconds speech_duration_ms: Current speech duration in milliseconds
@ -1547,7 +1548,21 @@ class ConnectionHandler:
if self.client_listen_mode == "manual": if self.client_listen_mode == "manual":
return return
# Check if meeting interruption thresholds # Check speech duration threshold
speech_ok = speech_duration_ms >= self.min_interrupt_speech_duration_ms
if not speech_ok:
return
# Check text length threshold (only for streaming ASR)
# Non-streaming ASR doesn't have real-time text during speech
from core.providers.asr.dto import InterfaceType
is_streaming_asr = (
self.asr is not None
and hasattr(self.asr, 'interface_type')
and self.asr.interface_type == InterfaceType.STREAM
)
if is_streaming_asr:
words = tokenize.split_words( words = tokenize.split_words(
self.asr_text_buffer, self.asr_text_buffer,
ignore_punctuation=True, ignore_punctuation=True,
@ -1555,14 +1570,18 @@ class ConnectionHandler:
retain_format=False, retain_format=False,
) )
asr_text_len = len(words) asr_text_len = len(words)
speech_ok = speech_duration_ms >= self.min_interrupt_speech_duration_ms
text_ok = asr_text_len >= self.min_interrupt_text_length text_ok = asr_text_len >= self.min_interrupt_text_length
if not text_ok:
if speech_ok and text_ok: return
self.logger.bind(tag=TAG).info( log_msg = (
f"Interrupt triggered: speech={speech_duration_ms:.0f}ms >= {self.min_interrupt_speech_duration_ms:.0f}ms, " f"Interrupt triggered (streaming): speech={speech_duration_ms:.0f}ms, "
f"text_len={asr_text_len} >= {self.min_interrupt_text_length}" f"text_len={asr_text_len} >= {self.min_interrupt_text_length}"
) )
else:
log_msg = f"Interrupt triggered (non-streaming): speech={speech_duration_ms:.0f}ms >= {self.min_interrupt_speech_duration_ms:.0f}ms"
self.logger.bind(tag=TAG).info(log_msg)
# Trigger interrupt # Trigger interrupt
self.client_abort = True self.client_abort = True
self.clear_queues() self.clear_queues()

View file

@ -14,7 +14,7 @@ from config.logger import setup_logging
from typing import Optional, Tuple, List from typing import Optional, Tuple, List
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
from .dto import ASRMessageType, ASRInputMessage from .dto import ASRMessageType, ASRInputMessage, InterfaceType
from queue import Queue, Empty from queue import Queue, Empty
TAG = __name__ TAG = __name__
@ -26,6 +26,8 @@ class ASRProviderBase(ABC):
def __init__(self): def __init__(self):
self.asr_input_queue = Queue[ASRInputMessage]() self.asr_input_queue = Queue[ASRInputMessage]()
self.asr_input_audio_format = "pcm" self.asr_input_audio_format = "pcm"
# Default to non-streaming, subclasses can override
self.interface_type = InterfaceType.NON_STREAM
# 打开音频通道 # 打开音频通道
async def open_audio_channels(self, conn): async def open_audio_channels(self, conn):

View file

@ -317,7 +317,7 @@ class VADStream(ABC):
asr_input_queue.put_nowait(asr_message) asr_input_queue.put_nowait(asr_message)
logger.bind(tag=TAG).info( logger.bind(tag=TAG).info(
f"ASR LAST message sent: total_speech={event.speech_duration:.2f}s, " f"ASR LAST message sent: total_speech={event.speech_duration:.0f}ms, "
f"audio={asr_message.audio_duration_ms:.0f}ms" f"audio={asr_message.audio_duration_ms:.0f}ms"
) )

View file

@ -567,9 +567,9 @@ TTS:
# ============================= Module Selection ================================ # ============================= Module Selection ================================
# =============================================================================== # ===============================================================================
selected_module: selected_module:
VAD: FsmnVAD # VAD: FsmnVAD
# VAD: SileroVAD VAD: SileroVAD
TurnDetection: TenTurnDetection # Set to TenTurnDetection to enable # TurnDetection: TenTurnDetection # Set to TenTurnDetection to enable
ASR: GroqASR ASR: GroqASR
# ASR: ByteplusStreamASR # ASR: ByteplusStreamASR
# LLM: GroqLLM # LLM: GroqLLM