Fix Race risks if process_audio is called concurrently.
This commit is contained in:
@@ -111,6 +111,7 @@ class DuplexPipeline:
|
|||||||
max_buffer_seconds = settings.max_audio_buffer_seconds if hasattr(settings, "max_audio_buffer_seconds") else 30
|
max_buffer_seconds = settings.max_audio_buffer_seconds if hasattr(settings, "max_audio_buffer_seconds") else 30
|
||||||
self._max_audio_buffer_bytes = int(settings.sample_rate * 2 * max_buffer_seconds)
|
self._max_audio_buffer_bytes = int(settings.sample_rate * 2 * max_buffer_seconds)
|
||||||
self._last_vad_status: str = "Silence"
|
self._last_vad_status: str = "Silence"
|
||||||
|
self._process_lock = asyncio.Lock()
|
||||||
|
|
||||||
# Interruption handling
|
# Interruption handling
|
||||||
self._interrupt_event = asyncio.Event()
|
self._interrupt_event = asyncio.Event()
|
||||||
@@ -208,6 +209,7 @@ class DuplexPipeline:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
async with self._process_lock:
|
||||||
# 1. Process through VAD
|
# 1. Process through VAD
|
||||||
vad_result = self.vad_processor.process(pcm_bytes, settings.chunk_size_ms)
|
vad_result = self.vad_processor.process(pcm_bytes, settings.chunk_size_ms)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user