mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Merge pull request #608 from evandroforks/fix_missing_pyaudio_import
Fix missing pyaudio blocking Anki from running
This commit is contained in:
commit
16d0bf24b4
1 changed files with 12 additions and 3 deletions
|
@ -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,12 @@ from aqt.qt import *
|
|||
from aqt.taskman import TaskManager
|
||||
from aqt.utils import restoreGeom, saveGeom, showWarning, startup_info
|
||||
|
||||
try:
|
||||
import pyaudio
|
||||
except:
|
||||
pyaudio = None
|
||||
|
||||
|
||||
# AV player protocol
|
||||
##########################################################################
|
||||
|
||||
|
@ -408,7 +412,6 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
|
|||
##########################################################################
|
||||
|
||||
|
||||
PYAU_FORMAT = pyaudio.paInt16
|
||||
PYAU_CHANNELS = 1
|
||||
PYAU_INPUT_INDEX: Optional[int] = None
|
||||
|
||||
|
@ -457,6 +460,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,
|
||||
|
@ -520,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)
|
||||
|
|
Loading…
Reference in a new issue