responsive_voice_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 from mycroft.tts import TTS, TTSValidator
17 
18 
20  def __init__(self, lang, config):
21  super(ResponsiveVoice, self).__init__(
22  lang, config, ResponsiveVoiceValidator(self), 'mp3',
23  ssml_tags=[]
24  )
25  self.clear_cache()
26  self.pitch = config.get("pitch", 0.5)
27  self.rate = config.get("rate", 0.5)
28  self.vol = config.get("vol", 1)
29  if "f" not in config.get("gender", "male"):
30  self.sv = "g1"
31  self.vn = "rjs"
32  else:
33  self.vn = self.sv = ""
34 
35  def get_tts(self, sentence, wav_file):
36  params = {"t": sentence, "tl": self.lang,
37  "pitch": self.pitch, "rate": self.rate,
38  "vol": self.vol, "sv": self.sv, "vn": self.vn}
39  base_url = "http://responsivevoice.org/responsivevoice/getvoice.php"
40  r = requests.get(base_url, params)
41  with open(wav_file, "w") as f:
42  f.write(r.content)
43  return wav_file, None
44 
45 
47  def __init__(self, tts):
48  super(ResponsiveVoiceValidator, self).__init__(tts)
49 
50  def validate_lang(self):
51  # TODO: Verify responsive voice can handle the requested language
52  pass
53 
55  r = requests.get("http://responsivevoice.org")
56  if r.status_code == 200:
57  return True
58  raise AssertionError("Could not reach http://responsivevoice.org")
59 
60  def get_tts_class(self):
61  return ResponsiveVoice


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