Allow user to select audio input device at startup

This commit is contained in:
Adolfo Reyna
2026-02-26 21:32:29 -05:00
parent e3bda17c7d
commit d75e19665f

View File

@@ -62,18 +62,24 @@ def main():
model = MarianMTModel.from_pretrained(model_id).to(device) model = MarianMTModel.from_pretrained(model_id).to(device)
translation_engines[lang_name] = (model, tokenizer) translation_engines[lang_name] = (model, tokenizer)
print("Loading Silero VAD model...") print("\nAvailable Audio Devices:")
vad_model = load_silero_vad() devices = sd.query_devices()
print(devices)
print("Models loaded.") try:
device_input = input("\nSelect input device index (or press Enter for default): ")
device_index = int(device_input) if device_input.strip() else None
except ValueError:
print("Invalid input, using default device.")
device_index = None
print(f"\nStarting live transcription & multiple translations... (Press Ctrl+C to stop)") print(f"\nStarting live transcription & multiple translations using device {device_index if device_index is not None else 'default'}... (Press Ctrl+C to stop)")
audio_buffer = [] audio_buffer = []
speech_started = False speech_started = False
try: try:
with sd.InputStream(samplerate=SAMPLERATE, channels=CHANNELS, callback=callback, blocksize=BLOCK_SIZE): with sd.InputStream(samplerate=SAMPLERATE, channels=CHANNELS, callback=callback, blocksize=BLOCK_SIZE, device=device_index):
while True: while True:
while not audio_queue.empty(): while not audio_queue.empty():
data = audio_queue.get() data = audio_queue.get()