hass-core/homeassistant/components/tts/demo.py
Pascal Vizeli 2dec38d8d4 TTS Component / Google speech platform (#4837)
* TTS Component / Google speech platform

* Change file backend handling / cache

* Use mimetype / rename Provider function / allow cache on service call

* Add a memcache for faster response

* Add demo platform

* First version of unittest

* Address comments

* improve error handling / address comments

* Add google unittest & check http response code

* Change url param handling

* add test for other language

* Change hash to sha256 for same hash on every os/hardware

* add unittest for receive demo data

* add test for error cases

* Test case load from file to mem over aiohttp server

* Use cache SpeechManager level, address other comments

* Add service for clear cache

* Update service.yaml

* add support for spliting google message
2016-12-12 23:23:08 -08:00

29 lines
705 B
Python

"""
Support for the demo speech service.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/demo/
"""
import os
from homeassistant.components.tts import Provider
def get_engine(hass, config):
"""Setup Demo speech component."""
return DemoProvider()
class DemoProvider(Provider):
"""Demo speech api provider."""
def get_tts_audio(self, message):
"""Load TTS from demo."""
filename = os.path.join(os.path.dirname(__file__), "demo.mp3")
try:
with open(filename, 'rb') as voice:
data = voice.read()
except OSError:
return
return ("mp3", data)