From b671c8e627bb4c084641b5937374c7ed38397f6a Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 4 May 2020 12:29:19 -0300 Subject: [PATCH 1/2] Fix missing pyaudio blocking Anki from running https://github.com/ankitects/anki/pull 606 Remove pyaudio as mandatory dependency --- qt/aqt/sound.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index cdd9b65d0..e6d0e8a15 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -13,8 +13,6 @@ from concurrent.futures import Future from operator import itemgetter from typing import Any, Callable, Dict, List, Optional, Tuple -import pyaudio - import aqt from anki.cards import Card from anki.lang import _ @@ -26,6 +24,14 @@ from aqt.qt import * from aqt.taskman import TaskManager from aqt.utils import restoreGeom, saveGeom, showWarning, startup_info +try: + import pyaudio +except: + print( + "Warning: pyaudio is not installed and audio recording will not work! Install it with: python3 -m pip install pyaudio" + ) + + # AV player protocol ########################################################################## @@ -408,7 +414,6 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer): ########################################################################## -PYAU_FORMAT = pyaudio.paInt16 PYAU_CHANNELS = 1 PYAU_INPUT_INDEX: Optional[int] = None @@ -457,6 +462,7 @@ class PyAudioThreadedRecorder(threading.Thread): rate = int(p.get_default_input_device_info()["defaultSampleRate"]) wait = int(rate * self.startupDelay) + PYAU_FORMAT = pyaudio.paInt16 stream = p.open( format=PYAU_FORMAT, From 0006269c01c89dd8e9c632b7b8ddf44817670b07 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 4 May 2020 23:45:06 -0300 Subject: [PATCH 2/2] Used showWarning asking the user to install pyaudio --- qt/aqt/sound.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index e6d0e8a15..d5f89737f 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -27,9 +27,7 @@ from aqt.utils import restoreGeom, saveGeom, showWarning, startup_info try: import pyaudio except: - print( - "Warning: pyaudio is not installed and audio recording will not work! Install it with: python3 -m pip install pyaudio" - ) + pyaudio = None # AV player protocol @@ -526,6 +524,11 @@ Recorder = PyAudioRecorder def getAudio(parent: QWidget, encode: bool = True) -> Optional[str]: "Record and return filename" + if not pyaudio: + showWarning( + "The Python pip `pyaudio` dependency is not installed and audio recording will not work!" + ) + return None # record first r = Recorder() mb = QMessageBox(parent)