Late-bind importing sounddevice, as it was slowing down aider startup

This commit is contained in:
Paul Gauthier 2023-08-19 15:18:46 -07:00
parent 4846317ef1
commit 963bc83a9c
3 changed files with 24 additions and 15 deletions

View file

@ -14,6 +14,8 @@ from .dump import dump # noqa: F401
class Commands:
voice = None
def __init__(self, io, coder, voice_language=None):
self.io = io
self.coder = coder
@ -441,11 +443,13 @@ class Commands:
def cmd_voice(self, args):
"Record and transcribe voice input"
v = voice.Voice()
if not v.is_audio_available():
self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?")
return
if not self.voice:
try:
self.voice = voice.Voice()
except voice.SoundDeviceError:
self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?")
return
history_iter = self.io.get_input_history()
@ -464,7 +468,7 @@ class Commands:
history.reverse()
history = "\n".join(history)
text = v.record_and_transcribe(history, language=self.voice_language)
text = self.voice.record_and_transcribe(history, language=self.voice_language)
if text:
self.io.add_to_input_history(text)
print()