Migrate to Deepgram STT, Silero v5 TTS, and fix wake word mic handling

This commit is contained in:
2026-01-07 17:59:18 +03:00
parent 7b79593cad
commit 53809c03f4
5 changed files with 233 additions and 89 deletions

View File

@@ -40,6 +40,24 @@ class WakeWordDetector:
"""
if not self.porcupine:
self.initialize()
# Ensure stream is open and active
if self.audio_stream is None or not self.audio_stream.is_active():
# If closed or None, we might need to recreate it.
# PyAudio streams once closed cannot be reopened usually?
# We should probably recreate it.
if self.audio_stream:
try:
self.audio_stream.close()
except: pass
self.audio_stream = self.pa.open(
rate=self.porcupine.sample_rate,
channels=1,
format=pyaudio.paInt16,
input=True,
frames_per_buffer=self.porcupine.frame_length
)
while True:
pcm = self.audio_stream.read(self.porcupine.frame_length, exception_on_overflow=False)
@@ -48,6 +66,9 @@ class WakeWordDetector:
keyword_index = self.porcupine.process(pcm)
if keyword_index >= 0:
print("✅ Wake word обнаружен!")
# Stop and CLOSE stream to release mic for STT
self.audio_stream.stop_stream()
self.audio_stream.close()
return True
def check_wakeword_once(self) -> bool:
@@ -59,6 +80,21 @@ class WakeWordDetector:
self.initialize()
try:
# Ensure stream is open/active
if self.audio_stream is None or not self.audio_stream.is_active():
# Re-open if needed (similar to wait_for_wakeword logic)
if self.audio_stream:
try:
self.audio_stream.close()
except: pass
self.audio_stream = self.pa.open(
rate=self.porcupine.sample_rate,
channels=1,
format=pyaudio.paInt16,
input=True,
frames_per_buffer=self.porcupine.frame_length
)
pcm = self.audio_stream.read(self.porcupine.frame_length, exception_on_overflow=False)
pcm = struct.unpack_from("h" * self.porcupine.frame_length, pcm)