forked from MycroftAI/mycroft-core
-
-
Notifications
You must be signed in to change notification settings - Fork 28
feat/fallback_stt #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d4baf5
feat/fallback_stt
JarbasAl bd41d89
add vosk
JarbasAl 9768a0b
license tests
JarbasAl de07f61
add stt unittests
JarbasAl c5acd88
add stt unittests
JarbasAl 1736cd9
test default plugins
JarbasAl 99d77d4
add fallback stt unittests
JarbasAl 5576258
disable py3.10 unittests temporarily
JarbasAl 29c17e0
test bad fallback stt configs
JarbasAl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from ovos_plugin_manager.stt import find_stt_plugins | ||
| from ovos_plugin_manager.tts import find_tts_plugins | ||
| from ovos_plugin_manager.wakewords import find_wake_word_plugins | ||
| from ovos_plugin_manager.audio import find_audio_service_plugins | ||
|
|
||
| from unittest import TestCase, mock | ||
|
|
||
|
|
||
| class TestFindDefaults(TestCase): | ||
| def test_ww(self): | ||
| expected = ["ovos-ww-plugin-pocketsphinx", | ||
| "ovos-ww-plugin-precise", | ||
| "ovos-precise-lite" # TODO rename for convention | ||
| ] | ||
| plugs = set(find_wake_word_plugins()) | ||
| for plug in expected: | ||
| self.assertIn(plug, plugs) | ||
|
|
||
| def test_stt(self): | ||
| expected = ["ovos-stt-plugin-chromium", | ||
| "ovos-stt-plugin-vosk", | ||
| "ovos-stt-plugin-vosk-streaming" | ||
| ] | ||
| plugs = set(find_stt_plugins()) | ||
| for plug in expected: | ||
| self.assertIn(plug, plugs) | ||
|
|
||
| def test_tts(self): | ||
| expected = ["ovos-tts-plugin-mimic", | ||
| "ovos-tts-plugin-mimic2", | ||
| "ovos-tts-plugin-responsivevoice", | ||
| "ovos-tts-plugin-google-tx" | ||
| ] | ||
| plugs = set(find_tts_plugins()) | ||
| for plug in expected: | ||
| self.assertIn(plug, plugs) | ||
|
|
||
| def test_audio(self): | ||
| # TODO rename plugins for convention | ||
| expected = ['ovos_common_play', | ||
| 'ovos_audio_simple'] | ||
| plugs = set(find_audio_service_plugins()) | ||
| for plug in expected: | ||
| self.assertIn(plug, plugs) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Copyright 2017 Mycroft AI Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| import sys | ||
| import unittest | ||
| from io import StringIO | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import mycroft.configuration | ||
| import mycroft.stt | ||
| from mycroft.client.speech.listener import RecognizerLoop | ||
| from mycroft.util.log import LOG | ||
| from ovos_stt_plugin_vosk import VoskKaldiSTT | ||
| from test.util import base_config | ||
|
|
||
|
|
||
| class TestSTT(unittest.TestCase): | ||
| def test_factory(self): | ||
| config = {'module': 'mycroft', | ||
| 'mycroft': {'uri': 'https://test.com'}} | ||
| stt = mycroft.stt.STTFactory.create(config) | ||
| self.assertEqual(type(stt), mycroft.stt.MycroftSTT) | ||
|
|
||
| config = {'stt': config} | ||
| stt = mycroft.stt.STTFactory.create(config) | ||
| self.assertEqual(type(stt), mycroft.stt.MycroftSTT) | ||
|
|
||
| @patch.object(mycroft.configuration.Configuration, 'get') | ||
| def test_factory_from_config(self, mock_get): | ||
| mycroft.stt.STTApi = MagicMock() | ||
| config = base_config() | ||
| config.merge( | ||
| { | ||
| 'stt': { | ||
| 'module': 'mycroft', | ||
| "fallback_module": "ovos-stt-plugin-vosk", | ||
| 'mycroft': {'uri': 'https://test.com'} | ||
| }, | ||
| 'lang': 'en-US' | ||
| }) | ||
| mock_get.return_value = config | ||
|
|
||
| stt = mycroft.stt.STTFactory.create() | ||
| self.assertEqual(type(stt), mycroft.stt.MycroftSTT) | ||
|
|
||
| @patch.object(mycroft.configuration.Configuration, 'get') | ||
| def test_mycroft_stt(self, mock_get): | ||
| mycroft.stt.STTApi = MagicMock() | ||
| config = base_config() | ||
| config.merge( | ||
| { | ||
| 'stt': { | ||
| 'module': 'mycroft', | ||
| 'mycroft': {'uri': 'https://test.com'} | ||
| }, | ||
| 'lang': 'en-US' | ||
| }) | ||
| mock_get.return_value = config | ||
|
|
||
| stt = mycroft.stt.MycroftSTT() | ||
| audio = MagicMock() | ||
| stt.execute(audio, 'en-us') | ||
| self.assertTrue(mycroft.stt.STTApi.called) | ||
|
|
||
| @patch.object(mycroft.configuration.Configuration, 'get') | ||
| def test_fallback_stt(self, mock_get): | ||
| config = base_config() | ||
| config.merge( | ||
| { | ||
| 'stt': { | ||
| 'module': 'mycroft', | ||
| "fallback_module": "ovos-stt-plugin-vosk", | ||
| 'mycroft': {'uri': 'https://test.com'} | ||
| }, | ||
| 'lang': 'en-US' | ||
| }) | ||
| mock_get.return_value = config | ||
|
|
||
| # check class matches | ||
| fallback_stt = RecognizerLoop.get_fallback_stt() | ||
| self.assertEqual(fallback_stt, VoskKaldiSTT) | ||
|
|
||
| @patch.object(mycroft.configuration.Configuration, 'get') | ||
| @patch.object(LOG, 'error') | ||
| @patch.object(LOG, 'warning') | ||
| def test_invalid_fallback_stt(self, mock_warn, mock_error, mock_get): | ||
| config = base_config() | ||
| config.merge( | ||
| { | ||
| 'stt': { | ||
| 'module': 'mycroft', | ||
| 'fallback_module': 'invalid', | ||
| 'mycroft': {'uri': 'https://test.com'} | ||
| }, | ||
| 'lang': 'en-US' | ||
| }) | ||
| mock_get.return_value = config | ||
|
|
||
| fallback_stt = RecognizerLoop.get_fallback_stt() | ||
| self.assertIsNone(fallback_stt) | ||
| mock_warn.assert_called_with("Could not find plugin: invalid") | ||
| mock_error.assert_called_with("Failed to create fallback STT") | ||
|
|
||
| @patch.object(mycroft.configuration.Configuration, 'get') | ||
| @patch.object(LOG, 'error') | ||
| @patch.object(LOG, 'warning') | ||
| def test_fallback_stt_not_set(self, mock_warn, mock_error, mock_get): | ||
| config = base_config() | ||
| config.merge( | ||
| { | ||
| 'stt': { | ||
| 'module': 'mycroft', | ||
| 'fallback_module': None, | ||
| 'mycroft': {'uri': 'https://test.com'} | ||
| }, | ||
| 'lang': 'en-US' | ||
| }) | ||
| mock_get.return_value = config | ||
|
|
||
| fallback_stt = RecognizerLoop.get_fallback_stt() | ||
| self.assertIsNone(fallback_stt) | ||
| mock_warn.assert_called_with("No fallback STT configured") | ||
| mock_error.assert_called_with("Failed to create fallback STT") | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.