allow running with pyaudio missing

This commit is contained in:
Damien Elmes 2019-02-13 09:36:39 +10:00
parent 7f8b4b89ae
commit ca710ab3f1
2 changed files with 19 additions and 6 deletions

View File

@ -297,12 +297,15 @@ addHook("unloadProfile", stopMplayer)
# PyAudio recording # PyAudio recording
########################################################################## ##########################################################################
import pyaudio try:
import wave import pyaudio
import wave
PYAU_FORMAT = pyaudio.paInt16 PYAU_FORMAT = pyaudio.paInt16
PYAU_CHANNELS = 1 PYAU_CHANNELS = 1
PYAU_INPUT_INDEX = None PYAU_INPUT_INDEX = None
except:
pyaudio = None
class _Recorder: class _Recorder:
@ -389,6 +392,9 @@ class PyAudioRecorder(_Recorder):
else: else:
return processingSrc return processingSrc
if not pyaudio:
PyAudioRecorder = None
# Audio interface # Audio interface
########################################################################## ##########################################################################

View File

@ -5,11 +5,18 @@ from aqt.qt import *
import time import time
from anki.sound import Recorder from anki.sound import Recorder
from aqt.utils import saveGeom, restoreGeom from aqt.utils import saveGeom, restoreGeom, showWarning
if not Recorder:
print("pyaudio not installed")
def getAudio(parent, encode=True): def getAudio(parent, encode=True):
"Record and return filename" "Record and return filename"
# record first # record first
if not Recorder:
showWarning("pyaudio not installed")
return
r = Recorder() r = Recorder()
mb = QMessageBox(parent) mb = QMessageBox(parent)
restoreGeom(mb, "audioRecorder") restoreGeom(mb, "audioRecorder")