From be9bbf21579fb1a74fcaade1d2acfec80f579bb1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 2 Jun 2021 12:14:20 +1000 Subject: [PATCH] catch all recording errors; mention permission https://forums.ankiweb.net/t/i-have-an-error-when-i-try-to-record-of-audio/10483 --- ftl/qt/qt-misc.ftl | 6 +++++- qt/aqt/errors.py | 3 --- qt/aqt/sound.py | 8 +++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ftl/qt/qt-misc.ftl b/ftl/qt/qt-misc.ftl index 47fe32019..80bc02bf3 100644 --- a/ftl/qt/qt-misc.ftl +++ b/ftl/qt/qt-misc.ftl @@ -29,7 +29,11 @@ qt-misc-manage-note-types = Manage Note Types qt-misc-name-exists = Name exists. qt-misc-non-unicode-text = qt-misc-optimizing = Optimizing... -qt-misc-please-connect-a-microphone-and-ensure = Please connect a microphone, and ensure other programs are not using the audio device. +qt-misc-unable-to-record = + Unable to record. Please ensure a microphone is connected, and Anki has permission to use the microphone. + If other programs are using your microphone, closing them may help. + + Original error: { $error } qt-misc-please-ensure-a-profile-is-open = Please ensure a profile is open and Anki is not busy, then try again. qt-misc-please-select-1-card = (please select 1 card) qt-misc-please-select-a-deck = Please select a deck. diff --git a/qt/aqt/errors.py b/qt/aqt/errors.py index 6150b47fb..31805a03a 100644 --- a/qt/aqt/errors.py +++ b/qt/aqt/errors.py @@ -78,9 +78,6 @@ class ErrorHandler(QObject): if "10013" in error: showWarning(tr.qt_misc_your_firewall_or_antivirus_program_is()) return - if "no default input" in error.lower(): - showWarning(tr.qt_misc_please_connect_a_microphone_and_ensure()) - return if "invalidTempFolder" in error: showWarning(self.tempFolderMsg()) return diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 55ce9d0a9..299c26cf0 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -17,6 +17,8 @@ from concurrent.futures import Future from operator import itemgetter from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, cast +from markdown import markdown + import aqt from anki import hooks from anki.cards import Card @@ -799,7 +801,11 @@ def record_audio( else: encode_mp3(mw, path, on_done) - _diag = RecordDialog(parent, mw, after_record) + try: + _diag = RecordDialog(parent, mw, after_record) + except Exception as e: + err_str = str(e) + showWarning(markdown(tr.qt_misc_unable_to_record(error=err_str))) # Legacy audio interface