fix: wrap sd.InputStream in try-except and fix config key name
- AudioRecorder.start() now catches InputStream errors gracefully
with a clear error message about microphone availability
- Fix config key mismatch: cli.py was reading "push_to_talk_key"
but config.py defines "record_key" -- now consistent
- Add format conversion from config format ("ctrl+b") to
prompt_toolkit format ("c-b")
This commit is contained in:
parent
a8838a7ae5
commit
fc893f98f4
2 changed files with 20 additions and 10 deletions
|
|
@ -291,13 +291,20 @@ class AudioRecorder:
|
|||
if cb:
|
||||
threading.Thread(target=cb, daemon=True).start()
|
||||
|
||||
self._stream = sd.InputStream(
|
||||
samplerate=SAMPLE_RATE,
|
||||
channels=CHANNELS,
|
||||
dtype=DTYPE,
|
||||
callback=_callback,
|
||||
)
|
||||
self._stream.start()
|
||||
try:
|
||||
self._stream = sd.InputStream(
|
||||
samplerate=SAMPLE_RATE,
|
||||
channels=CHANNELS,
|
||||
dtype=DTYPE,
|
||||
callback=_callback,
|
||||
)
|
||||
self._stream.start()
|
||||
except Exception as e:
|
||||
self._stream = None
|
||||
raise RuntimeError(
|
||||
f"Failed to open audio input stream: {e}. "
|
||||
"Check that a microphone is connected and accessible."
|
||||
) from e
|
||||
self._recording = True
|
||||
logger.info("Voice recording started (rate=%d, channels=%d)", SAMPLE_RATE, CHANNELS)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue