mary_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 import requests
16 
17 from mycroft.tts import TTSValidator
18 from mycroft.tts.remote_tts import RemoteTTS
19 
20 
22  PARAMS = {
23  'LOCALE': 'en_US',
24  'VOICE': 'cmu-slt-hsmm',
25  'INPUT_TEXT': 'Hello World',
26  'INPUT_TYPE': 'TEXT',
27  'AUDIO': 'WAVE_FILE',
28  'OUTPUT_TYPE': 'AUDIO'
29  }
30 
31  def __init__(self, lang, config):
32  super(MaryTTS, self).__init__(lang, config, '/process',
33  MaryTTSValidator(self))
34 
35  def build_request_params(self, sentence):
36  params = self.PARAMS.copy()
37  params['LOCALE'] = self.lang
38  params['VOICE'] = self.voice
39  params['INPUT_TEXT'] = sentence.encode('utf-8')
40  return params
41 
42 
44  def __init__(self, tts):
45  super(MaryTTSValidator, self).__init__(tts)
46 
47  def validate_lang(self):
48  # TODO
49  pass
50 
52  try:
53  resp = requests.get(self.tts.url + "/version", verify=False)
54  if resp.content.find('Mary TTS server') < 0:
55  raise Exception('Invalid MaryTTS server.')
56  except Exception:
57  raise Exception(
58  'MaryTTS server could not be verified. Check your connection '
59  'to the server: ' + self.tts.url)
60 
61  def get_tts_class(self):
62  return MaryTTS
def __init__(self, lang, config)
Definition: mary_tts.py:31
def build_request_params(self, sentence)
Definition: mary_tts.py:35


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