disable /voice if import soundfile failes #274

This commit is contained in:
Paul Gauthier 2023-10-12 07:00:51 -07:00
parent 87fb6c8fbb
commit 22eb344192
2 changed files with 12 additions and 3 deletions

View file

@ -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()

View file

@ -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):