added speed and emotion to Yandex tts (#5431)
* Added speed and emotion parameters. Refactored test's * Fixed float point arfs in url and added test for float point values
This commit is contained in:
1 parent
2fff8a5a11
commit
ccd2588cf7
2 files changed
+186
-19
No files matched your search
@@ -54,10 +54,17 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=en-US"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=200, content=b'test')
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -81,10 +88,17 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=ru-RU"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'ru-RU',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=200, content=b'test')
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -109,10 +123,17 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=ru-RU"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'ru-RU',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=200, content=b'test')
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -137,10 +158,18 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=en-US"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=200, exc=asyncio.TimeoutError())
|
||||
self._base_url, status=200,
|
||||
exc=asyncio.TimeoutError(), params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -164,10 +193,17 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=en-US"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=403, content=b'test')
|
||||
self._base_url, status=403, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -190,10 +226,17 @@ class TestTTSYandexPlatform(object):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
|
||||
"&speaker=alyss&key=1234567xx&text=HomeAssistant&lang=en-US"
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'alyss',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
url, status=200, content=b'test')
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
@@ -213,3 +256,108 @@ class TestTTSYandexPlatform(object):
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert len(calls) == 1
|
||||
|
||||
def test_service_say_specifed_emotion(self, aioclient_mock):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'evil',
|
||||
'speed': 1
|
||||
}
|
||||
aioclient_mock.get(
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
'platform': 'yandextts',
|
||||
'api_key': '1234567xx',
|
||||
'emotion': 'evil'
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, tts.DOMAIN):
|
||||
setup_component(self.hass, tts.DOMAIN, config)
|
||||
|
||||
self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
|
||||
tts.ATTR_MESSAGE: "HomeAssistant",
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert len(calls) == 1
|
||||
|
||||
def test_service_say_specified_low_speed(self, aioclient_mock):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': '0.1'
|
||||
}
|
||||
aioclient_mock.get(
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
'platform': 'yandextts',
|
||||
'api_key': '1234567xx',
|
||||
'speed': 0.1
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, tts.DOMAIN):
|
||||
setup_component(self.hass, tts.DOMAIN, config)
|
||||
|
||||
self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
|
||||
tts.ATTR_MESSAGE: "HomeAssistant",
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert len(calls) == 1
|
||||
|
||||
def test_service_say_specified_speed(self, aioclient_mock):
|
||||
"""Test service call say."""
|
||||
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
||||
url_param = {
|
||||
'text': 'HomeAssistant',
|
||||
'lang': 'en-US',
|
||||
'key': '1234567xx',
|
||||
'speaker': 'zahar',
|
||||
'format': 'mp3',
|
||||
'emotion': 'neutral',
|
||||
'speed': 2
|
||||
}
|
||||
aioclient_mock.get(
|
||||
self._base_url, status=200, content=b'test', params=url_param)
|
||||
|
||||
config = {
|
||||
tts.DOMAIN: {
|
||||
'platform': 'yandextts',
|
||||
'api_key': '1234567xx',
|
||||
'speed': 2
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, tts.DOMAIN):
|
||||
setup_component(self.hass, tts.DOMAIN, config)
|
||||
|
||||
self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
|
||||
tts.ATTR_MESSAGE: "HomeAssistant",
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert len(calls) == 1
|
||||
Reference in new issue
Block a user