2019-11-04 12:10:42 +00:00
|
|
|
"""Support for the demo for text to speech service."""
|
2016-12-13 07:23:08 +00:00
|
|
|
import os
|
|
|
|
|
2017-01-11 15:31:16 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-03-26 14:34:16 +00:00
|
|
|
from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
|
2017-01-11 15:31:16 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_LANGUAGES = ["en", "de"]
|
2017-01-11 15:31:16 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_LANG = "en"
|
2017-01-11 15:31:16 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{vol.Optional(CONF_LANG, default=DEFAULT_LANG): vol.In(SUPPORT_LANGUAGES)}
|
|
|
|
)
|
2016-12-13 07:23:08 +00:00
|
|
|
|
|
|
|
|
2019-11-05 21:39:15 +00:00
|
|
|
def get_engine(hass, config, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up Demo speech component."""
|
2019-11-07 12:43:43 +00:00
|
|
|
return DemoProvider(config.get(CONF_LANG, DEFAULT_LANG))
|
2016-12-13 07:23:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DemoProvider(Provider):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Demo speech API provider."""
|
2016-12-13 07:23:08 +00:00
|
|
|
|
2017-01-11 15:31:16 +00:00
|
|
|
def __init__(self, lang):
|
|
|
|
"""Initialize demo provider."""
|
|
|
|
self._lang = lang
|
2019-07-31 19:25:30 +00:00
|
|
|
self.name = "Demo"
|
2017-01-11 15:31:16 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def default_language(self):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Return the default language."""
|
2017-01-11 15:31:16 +00:00
|
|
|
return self._lang
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_languages(self):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Return list of supported languages."""
|
2017-01-11 15:31:16 +00:00
|
|
|
return SUPPORT_LANGUAGES
|
2016-12-27 16:01:22 +00:00
|
|
|
|
2017-01-21 07:35:18 +00:00
|
|
|
@property
|
|
|
|
def supported_options(self):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Return list of supported options like voice, emotionen."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return ["voice", "age"]
|
2017-01-21 07:35:18 +00:00
|
|
|
|
|
|
|
def get_tts_audio(self, message, language, options=None):
|
2016-12-13 07:23:08 +00:00
|
|
|
"""Load TTS from demo."""
|
2019-07-31 19:25:30 +00:00
|
|
|
filename = os.path.join(os.path.dirname(__file__), "tts.mp3")
|
2016-12-13 07:23:08 +00:00
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
with open(filename, "rb") as voice:
|
2016-12-13 07:23:08 +00:00
|
|
|
data = voice.read()
|
|
|
|
except OSError:
|
2017-01-11 15:31:16 +00:00
|
|
|
return (None, None)
|
2016-12-13 07:23:08 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
return ("mp3", data)
|