hass-core/homeassistant/components/demo/tts.py
Pascal Vizeli 005a1b2713
Add additional support over NC (#28527)
* Add voice support over NC

* Add disocery support for TTS / STT

* fix cloud TTS discovery

* Fix dev config

* Fix discovery

* Bump hass-nabucasa 0.25

* Add channel support

* Fix lint

* Update homeassistant/components/cloud/__init__.py

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* Update homeassistant/components/cloud/tts.py

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* Update homeassistant/components/cloud/tts.py

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* Update homeassistant/components/cloud/tts.py

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* bump hass-nabucasa

* Update tts.py

* fix lint
2019-11-05 22:39:15 +01:00

54 lines
1.4 KiB
Python

"""Support for the demo for text to speech service."""
import os
import voluptuous as vol
from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
SUPPORT_LANGUAGES = ["en", "de"]
DEFAULT_LANG = "en"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Optional(CONF_LANG, default=DEFAULT_LANG): vol.In(SUPPORT_LANGUAGES)}
)
def get_engine(hass, config, discovery_info=None):
"""Set up Demo speech component."""
return DemoProvider(config[CONF_LANG])
class DemoProvider(Provider):
"""Demo speech API provider."""
def __init__(self, lang):
"""Initialize demo provider."""
self._lang = lang
self.name = "Demo"
@property
def default_language(self):
"""Return the default language."""
return self._lang
@property
def supported_languages(self):
"""Return list of supported languages."""
return SUPPORT_LANGUAGES
@property
def supported_options(self):
"""Return list of supported options like voice, emotionen."""
return ["voice", "age"]
def get_tts_audio(self, message, language, options=None):
"""Load TTS from demo."""
filename = os.path.join(os.path.dirname(__file__), "tts.mp3")
try:
with open(filename, "rb") as voice:
data = voice.read()
except OSError:
return (None, None)
return ("mp3", data)