From 7b993a9bbbcc617dff37889e1d4fce04c54a1544 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 10 Aug 2023 16:55:45 -0300 Subject: [PATCH] gracefully handle missing portaudio --- aider/commands.py | 9 ++++++--- aider/voice.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index f2b10eb6e..ad56666a8 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -8,8 +8,7 @@ import git import tiktoken from prompt_toolkit.completion import Completion -from aider import prompts -from aider.voice import record_and_transcribe +from aider import prompts, voice from .dump import dump # noqa: F401 @@ -437,7 +436,11 @@ class Commands: def cmd_voice(self, args): "Record and transcribe voice input" - text = record_and_transcribe() + if not voice.is_audio_available(): + self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?") + return + + text = voice.record_and_transcribe() self.io.user_input(text, log_only=False) return text diff --git a/aider/voice.py b/aider/voice.py index e4fcc57f4..00a6259a7 100644 --- a/aider/voice.py +++ b/aider/voice.py @@ -3,12 +3,21 @@ import queue import tempfile import openai -import sounddevice as sd + +try: + import sounddevice as sd +except OSError: + sd = None + import soundfile as sf from .dump import dump # noqa: F401 +def is_audio_available(): + return sd is not None + + def record_and_transcribe(): q = queue.Queue()