Use speak2mary for MaryTTS integration and enable sound effects (#30805)

* Use speak2mary for MaryTTS integration and enable sound effects

* Replace static defaults for effects with user configured ones
This commit is contained in:
Markus Pöschl authored and Pascal Vizeli committed 2020-01-23 22:45:06 +01:00
1 parent fc95744bb7
commit 7fed328e1c
5 files changed
+108 -90

No files matched your search

+64 -38
View File
@@ -1,9 +1,12 @@
"""The tests for the MaryTTS speech platform."""
import asyncio
import os
import shutil
from urllib.parse import urlencode
from mock import Mock, patch
from homeassistant.components.media_player.const import (
ATTR_MEDIA_CONTENT_ID,
DOMAIN as DOMAIN_MP,
SERVICE_PLAY_MEDIA,
)
@@ -11,7 +14,6 @@ import homeassistant.components.tts as tts
from homeassistant.setup import setup_component
from tests.common import assert_setup_component, get_test_home_assistant, mock_service
from tests.components.tts.test_init import mutagen_mock # noqa: F401
class TestTTSMaryTTSPlatform:
@@ -21,14 +23,15 @@ class TestTTSMaryTTSPlatform:
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.url = "http://localhost:59125/process?"
self.url_param = {
self.host = "localhost"
self.port = 59125
self.params = {
"INPUT_TEXT": "HomeAssistant",
"INPUT_TYPE": "TEXT",
"AUDIO": "WAVE",
"VOICE": "cmu-slt-hsmm",
"OUTPUT_TYPE": "AUDIO",
"LOCALE": "en_US",
"AUDIO": "WAVE_FILE",
"VOICE": "cmu-slt-hsmm",
}
def teardown_method(self):
@@ -46,60 +49,83 @@ class TestTTSMaryTTSPlatform:
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
def test_service_say(self, aioclient_mock):
def test_service_say(self):
"""Test service call say."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
aioclient_mock.get(self.url, params=self.url_param, status=200, content=b"test")
conn = Mock()
response = Mock()
conn.getresponse.return_value = response
response.status = 200
response.read.return_value = b"audio"
config = {tts.DOMAIN: {"platform": "marytts"}}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
with patch("http.client.HTTPConnection", return_value=conn):
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
self.hass.block_till_done()
assert len(aioclient_mock.mock_calls) == 1
assert len(calls) == 1
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(".wav") != -1
conn.request.assert_called_with("POST", "/process", urlencode(self.params))
def test_service_say_timeout(self, aioclient_mock):
def test_service_say_with_effect(self):
"""Test service call say with effects."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
conn = Mock()
response = Mock()
conn.getresponse.return_value = response
response.status = 200
response.read.return_value = b"audio"
config = {
tts.DOMAIN: {"platform": "marytts", "effect": {"Volume": "amount:2.0;"}}
}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
with patch("http.client.HTTPConnection", return_value=conn):
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
self.hass.block_till_done()
assert len(calls) == 1
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(".wav") != -1
self.params.update(
{"effect_Volume_selected": "on", "effect_Volume_parameters": "amount:2.0;"}
)
conn.request.assert_called_with("POST", "/process", urlencode(self.params))
def test_service_say_http_error(self):
"""Test service call say."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
aioclient_mock.get(
self.url, params=self.url_param, status=200, exc=asyncio.TimeoutError()
)
conn = Mock()
response = Mock()
conn.getresponse.return_value = response
response.status = 500
response.reason = "test"
response.readline.return_value = "content"
config = {tts.DOMAIN: {"platform": "marytts"}}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
self.hass.block_till_done()
assert len(calls) == 0
assert len(aioclient_mock.mock_calls) == 1
def test_service_say_http_error(self, aioclient_mock):
"""Test service call say."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
aioclient_mock.get(self.url, params=self.url_param, status=403, content=b"test")
config = {tts.DOMAIN: {"platform": "marytts"}}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
with patch("http.client.HTTPConnection", return_value=conn):
self.hass.services.call(
tts.DOMAIN, "marytts_say", {tts.ATTR_MESSAGE: "HomeAssistant"}
)
self.hass.block_till_done()
assert len(calls) == 0
conn.request.assert_called_with("POST", "/process", urlencode(self.params))