From ed660183f03606e35f59652cd60df6bebf1ab125 Mon Sep 17 00:00:00 2001 From: jarbasai Date: Sun, 26 Nov 2017 21:00:17 +0000 Subject: [PATCH 1/3] ibm watson tts --- mycroft/tts/__init__.py | 5 ++-- mycroft/tts/ibm_tts.py | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 mycroft/tts/ibm_tts.py diff --git a/mycroft/tts/__init__.py b/mycroft/tts/__init__.py index ca40a5f914..a08cbdd60b 100644 --- a/mycroft/tts/__init__.py +++ b/mycroft/tts/__init__.py @@ -333,14 +333,15 @@ class TTSFactory(object): from mycroft.tts.mary_tts import MaryTTS from mycroft.tts.mimic_tts import Mimic from mycroft.tts.spdsay_tts import SpdSay - + from mycroft.tts.ibm_tts import WatsonTTS CLASSES = { "mimic": Mimic, "google": GoogleTTS, "marytts": MaryTTS, "fatts": FATTS, "espeak": ESpeak, - "spdsay": SpdSay + "spdsay": SpdSay, + "watson": WatsonTTS } @staticmethod diff --git a/mycroft/tts/ibm_tts.py b/mycroft/tts/ibm_tts.py new file mode 100644 index 0000000000..d38ac17608 --- /dev/null +++ b/mycroft/tts/ibm_tts.py @@ -0,0 +1,55 @@ +# Copyright 2017 Mycroft AI Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from mycroft.tts import TTSValidator +from mycroft.tts.remote_tts import RemoteTTS +from mycroft.configuration import Configuration + + +class WatsonTTS(RemoteTTS): + PARAMS = {'accept': 'audio/wav'} + + def __init__(self, lang, voice="en-US_AllisonVoice", + url="https://stream.watsonplatform.net/text-to-speech/api"): + super(WatsonTTS, self).__init__(lang, voice, url, '/v1/synthesize', + WatsonTTSValidator(self)) + self.type = "wav" + self.config = Configuration.get().get("tts", {}).get("watson", {}) + user = self.config.get("user") + password = self.config.get("password") + self.auth = (user, password) + + def build_request_params(self, sentence): + params = self.PARAMS.copy() + params['LOCALE'] = self.lang + params['voice'] = self.voice + params['text'] = sentence.encode('utf-8') + return params + + +class WatsonTTSValidator(TTSValidator): + def __init__(self, tts): + super(WatsonTTSValidator, self).__init__(tts) + + def validate_lang(self): + # TODO + pass + + def validate_connection(self): + # TODO + pass + + def get_tts_class(self): + return WatsonTTS From fd6ea82cabdfa0ac3c8a0607d82209bc826d80b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Fri, 22 Dec 2017 15:41:12 +0100 Subject: [PATCH 2/3] Fix Authentication for tts_ibm --- mycroft/tts/ibm_tts.py | 5 +++-- mycroft/tts/remote_tts.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mycroft/tts/ibm_tts.py b/mycroft/tts/ibm_tts.py index d38ac17608..3cf3a6e934 100644 --- a/mycroft/tts/ibm_tts.py +++ b/mycroft/tts/ibm_tts.py @@ -16,6 +16,7 @@ from mycroft.tts import TTSValidator from mycroft.tts.remote_tts import RemoteTTS from mycroft.configuration import Configuration +from requests.auth import HTTPBasicAuth class WatsonTTS(RemoteTTS): @@ -27,9 +28,9 @@ class WatsonTTS(RemoteTTS): WatsonTTSValidator(self)) self.type = "wav" self.config = Configuration.get().get("tts", {}).get("watson", {}) - user = self.config.get("user") + user = self.config.get("user") or self.config.get("username") password = self.config.get("password") - self.auth = (user, password) + self.auth = HTTPBasicAuth(user, password) def build_request_params(self, sentence): params = self.PARAMS.copy() diff --git a/mycroft/tts/remote_tts.py b/mycroft/tts/remote_tts.py index cc0e5c9ca7..7c1f9f96dc 100644 --- a/mycroft/tts/remote_tts.py +++ b/mycroft/tts/remote_tts.py @@ -32,6 +32,7 @@ class RemoteTTS(TTS): def __init__(self, lang, voice, url, api_path, validator): super(RemoteTTS, self).__init__(lang, voice, validator) self.api_path = api_path + self.auth = None self.url = remove_last_slash(url) self.session = FuturesSession() @@ -64,7 +65,7 @@ class RemoteTTS(TTS): def __request(self, p): return self.session.get( self.url + self.api_path, params=self.build_request_params(p), - timeout=10, verify=False) + timeout=10, verify=False, auth=self.auth) @abc.abstractmethod def build_request_params(self, sentence): From aed83da43f2914994b43b00c866b0436c4fa6db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Wed, 3 Jan 2018 21:26:27 +0100 Subject: [PATCH 3/3] Add basic validation --- mycroft/tts/ibm_tts.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mycroft/tts/ibm_tts.py b/mycroft/tts/ibm_tts.py index 3cf3a6e934..3626644089 100644 --- a/mycroft/tts/ibm_tts.py +++ b/mycroft/tts/ibm_tts.py @@ -49,8 +49,13 @@ class WatsonTTSValidator(TTSValidator): pass def validate_connection(self): - # TODO - pass + config = Configuration.get().get("tts", {}).get("watson", {}) + user = config.get("user") or config.get("username") + password = config.get("password") + if user and password: + return + else: + raise ValueError('user and/or password for IBM tts is not defined') def get_tts_class(self): return WatsonTTS