ibm_tts.py
Go to the documentation of this file.
1 # Copyright 2017 Mycroft AI Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 
16 from mycroft.tts import TTSValidator
17 from mycroft.tts.remote_tts import RemoteTTS
18 from mycroft.configuration import Configuration
19 from requests.auth import HTTPBasicAuth
20 
21 
23  PARAMS = {'accept': 'audio/wav'}
24 
25  def __init__(self, lang, config,
26  url="https://stream.watsonplatform.net/text-to-speech/api"):
27  super(WatsonTTS, self).__init__(lang, config, url, '/v1/synthesize',
28  WatsonTTSValidator(self))
29  self.type = "wav"
30  user = self.config.get("user") or self.config.get("username")
31  password = self.config.get("password")
32  api_key = self.config.get("apikey")
33  if api_key is None:
34  self.auth = HTTPBasicAuth(user, password)
35  else:
36  self.auth = HTTPBasicAuth("apikey", api_key)
37 
38  def build_request_params(self, sentence):
39  params = self.PARAMS.copy()
40  params['LOCALE'] = self.lang
41  params['voice'] = self.voice
42  params['text'] = sentence.encode('utf-8')
43  return params
44 
45 
47  def __init__(self, tts):
48  super(WatsonTTSValidator, self).__init__(tts)
49 
50  def validate_lang(self):
51  # TODO
52  pass
53 
55  config = Configuration.get().get("tts", {}).get("watson", {})
56  user = config.get("user") or config.get("username")
57  password = config.get("password")
58  apikey = config.get("apikey")
59  if user and password or apikey:
60  return
61  else:
62  raise ValueError('user/pass or apikey for IBM tts is not defined')
63 
64  def get_tts_class(self):
65  return WatsonTTS
def __init__(self, lang, config, url="https://stream.watsonplatform.net/text-to-speech/api")
Definition: ibm_tts.py:26
def get(phrase, lang=None, context=None)
def build_request_params(self, sentence)
Definition: ibm_tts.py:38


mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:40