Skip to content

Commit 114091e

Browse files
committed
feat/fallback_stt
1 parent b01d2b6 commit 114091e

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

mycroft/client/speech/listener.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15+
import json
1516
import time
17+
from queue import Queue, Empty
1618
from threading import Thread
19+
1720
import pyaudio
1821
from pyee import EventEmitter
22+
1923
from mycroft.client.speech.hotword_factory import HotWordFactory
2024
from mycroft.client.speech.mic import MutableMicrophone, ResponsiveRecognizer
2125
from mycroft.configuration import Configuration
2226
from mycroft.metrics import Stopwatch, report_timing
2327
from mycroft.session import SessionManager
2428
from mycroft.stt import STTFactory
25-
from mycroft.util.log import LOG
2629
from mycroft.util import find_input_device
27-
from queue import Queue, Empty
28-
import json
30+
from mycroft.util.log import LOG
2931

3032
MAX_MIC_RESTARTS = 20
3133

@@ -195,7 +197,14 @@ def send_unknown_intent():
195197

196198
try:
197199
# Invoke the STT engine on the audio clip
198-
text = self.loop.stt.execute(audio, language=lang)
200+
try:
201+
text = self.loop.stt.execute(audio, language=lang)
202+
except Exception as e:
203+
if self.loop.fallback_stt:
204+
LOG.warning(f"Using fallback STT, main plugin failed: {e}")
205+
text = self.loop.fallback_stt.execute(audio, language=lang)
206+
else:
207+
raise e
199208
if text is not None:
200209
text = text.lower().strip()
201210
LOG.debug("STT: " + text)
@@ -240,23 +249,25 @@ class RecognizerLoop(EventEmitter):
240249
(optional, can be set later via self.bind )
241250
"""
242251

243-
def __init__(self, bus, watchdog=None, stt=None):
252+
def __init__(self, bus, watchdog=None, stt=None, fallback_stt=None):
244253
super(RecognizerLoop, self).__init__()
245254
self._watchdog = watchdog
246255
self.mute_calls = 0
247256
self.stt = stt
257+
self.fallback_stt = fallback_stt
248258
self.bus = bus
249259
self.engines = {}
250-
self.stt = None
251260
self.queue = None
252261
self.audio_consumer = None
253262
self.audio_producer = None
254263
self.responsive_recognizer = None
255264

256265
self._load_config()
257266

258-
def bind(self, stt):
267+
def bind(self, stt, fallback_stt=None):
259268
self.stt = stt
269+
if fallback_stt:
270+
self.fallback_stt = fallback_stt
260271

261272
def _load_config(self):
262273
"""Load configuration parameters from configuration."""
@@ -325,6 +336,20 @@ def start_async(self):
325336
self.state.running = True
326337
if not self.stt:
327338
self.stt = STTFactory.create()
339+
if not self.fallback_stt:
340+
stt_config = Configuration.get().get('stt', {})
341+
engine = stt_config.get("fallback_module")
342+
if not engine:
343+
LOG.warning("No fallback STT configured")
344+
else:
345+
plugin_config = stt_config.get(engine) or {}
346+
plugin_config["lang"] = plugin_config.get("lang") or \
347+
self.config_core.get("lang", "en-us")
348+
try:
349+
self.fallback_stt = STTFactory.create({"module": engine,
350+
engine: plugin_config})
351+
except Exception as e:
352+
LOG.error(f"Failed to create fallback STT")
328353
self.queue = Queue()
329354
self.audio_consumer = AudioConsumer(self)
330355
self.audio_consumer.start()

mycroft/configuration/mycroft.conf

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,8 @@
432432
"stt": {
433433
// Engine. Options: "mycroft", "google", "wit", "ibm", "kaldi", "bing",
434434
// "houndify", "deepspeech_server", "govivace", "yandex"
435-
"module": "mycroft"
436-
// "deepspeech_server": {
437-
// "uri": "http://localhost:8080/stt"
438-
// },
439-
// "kaldi": {
440-
// "uri": "http://localhost:8080/client/dynamic/recognize"
441-
// },
442-
//"govivace": {
443-
// "uri": "https://services.govivace.com:49149/telephony",
444-
// "credential": {
445-
// "token": "xxxxx"
446-
// }
447-
//}
435+
"module": "mycroft",
436+
"fallback_module": "ovos-stt-plugin-vosk"
448437
},
449438

450439
// Text to Speech parameters

mycroft/stt/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ def execute(self, audio, language=None):
6363

6464
class STTFactory(OVOSSTTFactory):
6565
@staticmethod
66-
def create():
67-
config = Configuration.get().get("stt", {})
66+
def create(config=None):
67+
config = config or Configuration.get().get("stt", {})
6868
module = config.get("module", "mycroft")
69+
LOG.info(f"Creating STT engine: {module}")
6970
if module == "mycroft":
7071
return MycroftSTT()
7172
return OVOSSTTFactory.create(config)

requirements/minimal.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ mycroft-messagebus-client~=0.9.1,!=0.9.2,!=0.9.3
44
psutil~=5.6.6
55
combo-lock~=0.2
66
ovos-utils~=0.0.18
7-
ovos-plugin-manager~=0.0.10
7+
ovos-plugin-manager~=0.0.11a1

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ combo-lock~=0.2
99
PyYAML~=5.4
1010

1111
ovos-utils~=0.0.18
12-
ovos-plugin-manager~=0.0.10
12+
ovos-plugin-manager~=0.0.11a1
1313
ovos-tts-plugin-mimic>=0.2.6
1414
ovos-tts-plugin-mimic2>=0.1.4
1515
ovos-tts-plugin-google-tx>=0.0.3

0 commit comments

Comments
 (0)