fix: select audio input device via env

This commit is contained in:
2026-03-12 13:03:50 +03:00
parent 6769486e83
commit e9f26f8050
4 changed files with 128 additions and 2 deletions

View File

@@ -37,7 +37,9 @@ class WakeWordDetector:
)
# Используем общий экземпляр PyAudio
self.pa = get_audio_manager().get_pyaudio()
audio_manager = get_audio_manager()
self.pa = audio_manager.get_pyaudio()
self._input_device_index = audio_manager.get_input_device_index()
self._open_stream()
print(f"🎤 Ожидание wake word 'Alexandr' (sens={PORCUPINE_SENSITIVITY:.2f})...")
@@ -54,12 +56,17 @@ class WakeWordDetector:
pass
# Открываем поток с параметрами, которые требует Porcupine
kwargs = {}
if getattr(self, "_input_device_index", None) is not None:
kwargs["input_device_index"] = self._input_device_index
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,
**kwargs,
)
self._stream_closed = False