bing_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 TTS, TTSValidator
17 from mycroft.configuration import Configuration
18 
19 
20 class BingTTS(TTS):
21  def __init__(self, lang, config):
22  super(BingTTS, self).__init__(lang, config, BingTTSValidator(self))
23  self.type = 'wav'
24  from bingtts import Translator
25  self.config = Configuration.get().get("tts", {}).get("bing", {})
26  api = self.config.get("api_key")
27  self.bing = Translator(api)
28  self.gender = self.config.get("gender", "Male")
29  self.format = self.config.get("format", "riff-16khz-16bit-mono-pcm")
30 
31  def get_tts(self, sentence, wav_file):
32  output = self.bing.speak(sentence, self.lang, self.gender,
33  self.format)
34  with open(wav_file, "w") as f:
35  f.write(output)
36  return (wav_file, None) # No phonemes
37 
38 
40  def __init__(self, tts):
41  super(BingTTSValidator, self).__init__(tts)
42 
44  try:
45  from bingtts import Translator
46  except ImportError:
47  raise Exception(
48  'BingTTS dependencies not installed, please run pip install '
49  'git+https://github.com/westparkcom/Python-Bing-TTS.git ')
50 
51  def validate_lang(self):
52  # TODO
53  pass
54 
56  # TODO
57  pass
58 
59  def get_tts_class(self):
60  return BingTTS
def get_tts(self, sentence, wav_file)
Definition: bing_tts.py:31
def __init__(self, lang, config)
Definition: bing_tts.py:21
def get(phrase, lang=None, context=None)


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