Add configurable input device selection

This commit is contained in:
2026-03-01 12:49:39 +03:00
parent a87840c78d
commit 7ca6958488
6 changed files with 50 additions and 2 deletions

View File

@@ -128,13 +128,16 @@ class SpeechRecognizer:
def _get_stream(self):
"""Открывает аудиопоток PyAudio, если он еще не открыт."""
if self.stream is None:
device_index, device_info = get_audio_manager().resolve_input_device()
self.stream = self.pa.open(
rate=SAMPLE_RATE,
channels=1,
format=pyaudio.paInt16,
input=True,
input_device_index=device_index,
frames_per_buffer=4096,
)
print(f"🎙️ STT input: {device_info.get('name', 'unknown')}")
return self.stream
async def _process_audio(

View File

@@ -54,14 +54,18 @@ class WakeWordDetector:
pass
# Открываем поток с параметрами, которые требует Porcupine
device_index, device_info = get_audio_manager().resolve_input_device()
self.audio_stream = self.pa.open(
rate=self.porcupine.sample_rate,
channels=1,
format=pyaudio.paInt16,
input=True,
input_device_index=device_index,
frames_per_buffer=self.porcupine.frame_length,
)
self._stream_closed = False
device_name = device_info.get("name", "unknown")
print(f"🎙️ Wake word input: {device_name}")
def stop_monitoring(self):
"""Явная остановка и закрытие потока (чтобы освободить микрофон для других задач)."""