def test_stt(self, mock_get): mycroft.stt.STTApi = mock.MagicMock() config = base_config() config.merge( { 'stt': { 'module': 'mycroft', 'mycroft': {'uri': 'https://test.com'} }, 'lang': 'en-US' }) mock_get.return_value = config class TestSTT(mycroft.stt.STT): def execute(self, audio, language=None): pass stt = TestSTT() self.assertEqual(stt.lang, 'en-US') config['lang'] = 'en-us' # Check that second part of lang gets capitalized stt = TestSTT() self.assertEqual(stt.lang, 'en-US') # Check that it works with two letters config['lang'] = 'sv' stt = TestSTT() self.assertEqual(stt.lang, 'sv')
def test_stt(self, mock_get): owo.stt.STTApi = mock.MagicMock() config = base_config() config.merge({ 'stt': { 'module': 'OwO', 'OwO': { 'uri': 'https://test.com' } }, 'lang': 'en-US' }) mock_get.return_value = config class TestSTT(owo.stt.STT): def execute(self, audio, language=None): pass stt = TestSTT() self.assertEqual(stt.lang, 'en-US') config['lang'] = 'en-us' # Check that second part of lang gets capitalized stt = TestSTT() self.assertEqual(stt.lang, 'en-US') # Check that it works with two letters config['lang'] = 'sv' stt = TestSTT() self.assertEqual(stt.lang, 'sv')
def test_kaldi_stt(self, mock_get, mock_post): owo.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'kaldi', 'kaldi': { 'uri': 'https://test.com' }, }, 'lang': 'en-US' }) mock_get.return_value = config kaldiResponse = mock.MagicMock() kaldiResponse.json.return_value = { 'hypotheses': [{ 'utterance': ' [noise] text' }, { 'utterance': ' asdf' }] } mock_post.return_value = kaldiResponse audio = mock.MagicMock() stt = owo.stt.KaldiSTT() self.assertEquals(stt.execute(audio), 'text')
def setUp(self): with patch('mycroft.configuration.Configuration.get') as \ mock_config_get: conf = base_config() conf['hotwords']['hey mycroft']['module'] = 'pocketsphinx' mock_config_get.return_value = conf rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def setUp(self): with mock.patch('mycroft.configuration.Configuration.get') as \ mock_config_get: conf = base_config() conf['hotwords']['hey mycroft']['module'] = 'pocketsphinx' mock_config_get.return_value = conf rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def test_ibm_stt(self, mock_get, mock_post): import json config = base_config() config.merge({ 'stt': { 'module': 'ibm', 'ibm': { 'credential': { 'token': 'FOOBAR' }, 'url': 'https://test.com' }, }, 'lang': 'en-US' }) mock_get.return_value = config requests_object = MagicMock() requests_object.status_code = 200 requests_object.text = json.dumps({ 'results': [{ 'alternatives': [{ 'confidence': 0.96, 'transcript': 'sample response' }], 'final': True }], 'result_index': 0 }) mock_post.return_value = requests_object audio = MagicMock() audio.sample_rate = 16000 stt = mycroft.stt.IBMSTT() stt.execute(audio) test_url_base = 'https://test.com/v1/recognize' mock_post.assert_called_with(test_url_base, auth=('apikey', 'FOOBAR'), headers={ 'Content-Type': 'audio/x-flac', 'X-Watson-Learning-Opt-Out': 'true' }, data=audio.get_flac_data(), params={ 'model': 'en-US_BroadbandModel', 'profanity_filter': 'false' })
def test_factory(self, mock_get): mycroft.stt.STTApi = mock.MagicMock() config = base_config() config.merge( { 'stt': { 'module': 'mycroft', 'wit': {'credential': {'token': 'FOOBAR'}}, 'google': {'credential': {'token': 'FOOBAR'}}, 'bing': {'credential': {'token': 'FOOBAR'}}, 'houndify': {'credential': {'client_id': 'FOO', "client_key": "BAR"}}, 'google_cloud': { 'credential': { 'json': {} } }, 'ibm': {'credential': {'token': 'FOOBAR'}}, 'kaldi': {'uri': 'https://test.com'}, 'mycroft': {'uri': 'https://test.com'} }, 'lang': 'en-US' }) mock_get.return_value = config stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.MycroftSTT) config['stt']['module'] = 'google' stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.GoogleSTT) config['stt']['module'] = 'google_cloud' stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.GoogleCloudSTT) config['stt']['module'] = 'ibm' stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.IBMSTT) config['stt']['module'] = 'kaldi' stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.KaldiSTT) config['stt']['module'] = 'wit' stt = mycroft.stt.STTFactory.create() self.assertEquals(type(stt), mycroft.stt.WITSTT)
def test_mycroft_stt(self, mock_get): mycroft.stt.STTApi = mock.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 = mock.MagicMock() stt.execute(audio, 'en-us') self.assertTrue(mycroft.stt.STTApi.called)
def test_bing_stt(self, mock_get): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge( { 'stt': { 'module': 'bing', 'bing': {'credential': {'token': 'FOOBAR'}}, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = mycroft.stt.BingSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_bing.called)
def test_OwO_stt(self, mock_get): owo.stt.STTApi = mock.MagicMock() config = base_config() config.merge({ 'stt': { 'module': 'OwO', 'OwO': { 'uri': 'https://test.com' } }, 'lang': 'en-US' }) mock_get.return_value = config stt = owo.stt.OwOSTT() audio = mock.MagicMock() stt.execute(audio, 'en-us') self.assertTrue(owo.stt.STTApi.called)
def test_mycroft_stt(self, mock_get): mycroft.stt.STTApi = mock.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 = mock.MagicMock() stt.execute(audio, 'en-us') self.assertTrue(mycroft.stt.STTApi.called)
def test_houndify_stt(self, mock_get): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge( { 'stt': { 'module': 'houndify', 'houndify': {'credential': { 'client_id': 'FOO', 'client_key': "BAR"}} }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = mycroft.stt.HoundifySTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_houndify.called)
def testRecognizer(self, mock_config_get): test_config = base_config() mock_config_get.return_value = test_config # Test "Hey OwO" rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey OwO") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey OwO")
def testRecognizer(self, mock_config_get): test_config = base_config() mock_config_get.return_value = test_config # Test "Hey Mycroft" rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft")
def test_ibm_stt(self, mock_get): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge( { 'stt': { 'module': 'ibm', 'ibm': { 'credential': {'username': '******', 'password': '******'} }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = mycroft.stt.IBMSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_ibm.called)
def testRecognitionFallback(self, mock_config_get): """If language config doesn't exist set default (english)""" conf = base_config() conf['hotwords']['hey mycroft'] = { 'lang': 'DOES NOT EXIST', 'module': 'pocketsphinx', 'phonemes': 'HH EY . M AY K R AO F T', 'threshold': 1e-90 } conf['lang'] = 'DOES NOT EXIST' mock_config_get.return_value = conf rl = RecognizerLoop() ps_hotword = RecognizerLoop.create_wake_word_recognizer(rl) expected = 'en-us' res = ps_hotword.decoder.get_config().get_string('-hmm') self.assertEqual(expected, res.split('/')[-2]) self.assertEqual('does not exist', ps_hotword.lang)
def test_wit_stt(self, mock_get): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'wit', 'wit': { 'credential': { 'token': 'FOOBAR' } }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = mycroft.stt.WITSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_wit.called)
def test_bing_stt(self, mock_get): owo.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'bing', 'bing': { 'credential': { 'token': 'FOOBAR' } }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = owo.stt.BingSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_bing.called)
def test_google_cloud_stt(self, mock_get): owo.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'google_cloud', 'google_cloud': { 'credential': { 'json': {} } }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = owo.stt.GoogleCloudSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_google_cloud.called)
def test_houndify_stt(self, mock_get): owo.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'houndify', 'houndify': { 'credential': { 'client_id': 'FOO', 'client_key': "BAR" } } }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = owo.stt.HoundifySTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_houndify.called)
def test_ibm_stt(self, mock_get): owo.stt.Recognizer = mock.MagicMock config = base_config() config.merge({ 'stt': { 'module': 'ibm', 'ibm': { 'credential': { 'username': '******', 'password': '******' } }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = owo.stt.IBMSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_ibm.called)
def test_google_cloud_stt(self, mock_get): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge( { 'stt': { 'module': 'google_cloud', 'google_cloud': { 'credential': { 'json': {} } }, }, 'lang': 'en-US' }) mock_get.return_value = config audio = mock.MagicMock() stt = mycroft.stt.GoogleCloudSTT() stt.execute(audio) self.assertTrue(stt.recognizer.recognize_google_cloud.called)
def testHotwordConfig(self, mock_config_get): """Ensure that the fallback method collecting phonemes etc. from the listener config works. """ test_config = base_config() mock_config_get.return_value = test_config # Set fallback values test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' test_config['listener']['threshold'] = 1e-90 steve_conf = { 'model': 'pocketsphinx', 'phonemes': 'S T IY V .', 'threshold': 1e-42 } test_config['hotwords']['steve'] = steve_conf test_config['listener']['wake_word'] = 'steve' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, 'steve') # Ensure phonemes and threshold are poulated from listener config # if they're missing # Set fallback values test_config['listener']['phonemes'] = 'S T IY V .' test_config['listener']['threshold'] = 1e-90 steve_conf = { 'model': 'pocketsphinx' } test_config['hotwords']['steve'] = steve_conf test_config['listener']['wake_word'] = 'steve' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, 'steve') self.assertEqual(rl.wakeword_recognizer.phonemes, 'S T IY V .')
def test_kaldi_stt(self, mock_get, mock_post): mycroft.stt.Recognizer = mock.MagicMock config = base_config() config.merge( { 'stt': { 'module': 'kaldi', 'kaldi': {'uri': 'https://test.com'}, }, 'lang': 'en-US' }) mock_get.return_value = config kaldiResponse = mock.MagicMock() kaldiResponse.json.return_value = { 'hypotheses': [{'utterance': ' [noise] text'}, {'utterance': ' asdf'}] } mock_post.return_value = kaldiResponse audio = mock.MagicMock() stt = mycroft.stt.KaldiSTT() self.assertEquals(stt.execute(audio), 'text')
def testListenerConfig(self, mock_config_get): """Ensure that the fallback method collecting phonemes etc. from the listener config works. """ test_config = base_config() mock_config_get.return_value = test_config # Test "Hey Mycroft" rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' test_config['listener']['threshold'] = 1e-90 rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft")
# 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. # from unittest import TestCase, mock from mycroft.configuration import Configuration from mycroft.messagebus import Message from mycroft.skills.intent_service import (ContextManager, IntentService, _get_message_lang) from test.util import base_config # Setup configurations to use with default language tests BASE_CONF = base_config() BASE_CONF['lang'] = 'it-it' NO_LANG_CONF = base_config() NO_LANG_CONF.pop('lang') class MockEmitter(object): def __init__(self): self.reset() def emit(self, message): self.types.append(message.msg_type) self.results.append(message.data) def get_types(self):
def setUp(self): with mock.patch('owo.configuration.Configuration.get') as \ mock_config_get: mock_config_get.return_value = base_config() rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
import mock from adapt.intent import IntentBuilder from os.path import join, dirname, abspath from re import error from datetime import datetime from mycroft.configuration import Configuration from mycroft.messagebus.message import Message from mycroft.skills.skill_data import load_regex_from_file, load_regex, \ load_vocab_from_file, load_vocabulary from mycroft.skills.core import MycroftSkill, load_skill, \ create_skill_descriptor, open_intent_envelope from test.util import base_config BASE_CONF = base_config() class MockEmitter(object): def __init__(self): self.reset() def emit(self, message): self.types.append(message.type) self.results.append(message.data) def get_types(self): return self.types def get_results(self): return self.results
# 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 unittest from copy import copy from unittest.mock import MagicMock, patch import mycroft.api import mycroft.configuration from test.util import base_config CONFIG = base_config() CONFIG.merge( { 'data_dir': '/opt/mycroft', 'server': { 'url': 'https://api-test.mycroft.ai', 'version': 'v1', 'update': True, 'metrics': False } } ) mycroft.api.requests.post = MagicMock()
def setUp(self): with mock.patch('mycroft.configuration.Configuration.get') as \ mock_config_get: mock_config_get.return_value = base_config() rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def test_factory(self, mock_get): owo.stt.STTApi = mock.MagicMock() config = base_config() config.merge({ 'stt': { 'module': 'OwO', 'wit': { 'credential': { 'token': 'FOOBAR' } }, 'google': { 'credential': { 'token': 'FOOBAR' } }, 'bing': { 'credential': { 'token': 'FOOBAR' } }, 'houndify': { 'credential': { 'client_id': 'FOO', "client_key": "BAR" } }, 'google_cloud': { 'credential': { 'json': {} } }, 'ibm': { 'credential': { 'token': 'FOOBAR' } }, 'kaldi': { 'uri': 'https://test.com' }, 'OwO': { 'uri': 'https://test.com' } }, 'lang': 'en-US' }) mock_get.return_value = config stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.OwOSTT) config['stt']['module'] = 'google' stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.GoogleSTT) config['stt']['module'] = 'google_cloud' stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.GoogleCloudSTT) config['stt']['module'] = 'ibm' stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.IBMSTT) config['stt']['module'] = 'kaldi' stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.KaldiSTT) config['stt']['module'] = 'wit' stt = owo.stt.STTFactory.create() self.assertEquals(type(stt), owo.stt.WITSTT)
# 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 unittest from copy import copy import mock import mycroft.api import mycroft.configuration from mycroft.util.log import LOG from test.util import base_config CONFIG = base_config() CONFIG.merge( { 'data_dir': '/opt/mycroft', 'server': { 'url': 'https://api-test.mycroft.ai', 'version': 'v1', 'update': True, 'metrics': False } } ) mycroft.api.requests.post = mock.MagicMock()