From 22eb344192f665ea43ebffc51993ba8e2beb6486 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 12 Oct 2023 07:00:51 -0700 Subject: [PATCH] disable /voice if import soundfile failes #274 --- aider/commands.py | 4 +++- aider/voice.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 9ab52cb2f..110a1cda7 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -457,7 +457,9 @@ class Commands: try: self.voice = voice.Voice() except voice.SoundDeviceError: - self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?") + self.io.tool_error( + "Unable to import `sounddevice` and/or `soundfile`, is portaudio installed?" + ) return history_iter = self.io.get_input_history() diff --git a/aider/voice.py b/aider/voice.py index 78f94f4ae..3ee9651ad 100644 --- a/aider/voice.py +++ b/aider/voice.py @@ -5,7 +5,12 @@ import time import numpy as np import openai -import soundfile as sf + +try: + import soundfile as sf +except (OSError, ModuleNotFoundError): + sf = None + from prompt_toolkit.shortcuts import prompt from .dump import dump # noqa: F401 @@ -23,12 +28,14 @@ class Voice: threshold = 0.15 def __init__(self): + if sf is None: + raise SoundDeviceError try: print("Initializing sound device...") import sounddevice as sd self.sd = sd - except OSError: + except (OSError, ModuleNotFoundError): raise SoundDeviceError def callback(self, indata, frames, time, status):