18 from threading
import Thread
19 from time
import time, sleep
22 from os.path
import exists, join, expanduser
24 from mycroft
import MYCROFT_ROOT_PATH
31 config = Configuration.get().
get(
"tts").
get(
"mimic")
32 data_dir = expanduser(Configuration.get()[
'data_dir'])
34 BIN = config.get(
"path",
35 os.path.join(MYCROFT_ROOT_PATH,
'mimic',
'bin',
'mimic'))
37 if not os.path.isfile(BIN):
39 import distutils.spawn
41 BIN = distutils.spawn.find_executable(
"mimic")
43 SUBSCRIBER_VOICES = {
'trinity': join(data_dir,
'voices/mimic_tn')}
48 Function to download all premium voices, starting with 49 the currently selected if applicable 52 def make_executable(dest):
53 """ Call back function to make the downloaded file executable. """ 54 LOG.info(
'Make executable')
57 os.chmod(dest, st.st_mode | stat.S_IEXEC)
60 voice_file = SUBSCRIBER_VOICES.get(selected_voice)
61 if voice_file
is not None and not exists(voice_file):
62 LOG.info(
'voice doesn\'t exist, downloading')
63 url =
DeviceApi().get_subscriber_voice_url(selected_voice)
66 dl =
download(url, voice_file, make_executable)
71 LOG.debug(
'{} is not available for this architecture' 72 .format(selected_voice))
75 for voice
in SUBSCRIBER_VOICES:
76 voice_file = SUBSCRIBER_VOICES[voice]
77 if not exists(voice_file):
78 url =
DeviceApi().get_subscriber_voice_url(voice)
81 dl =
download(url, voice_file, make_executable)
86 LOG.debug(
'{} is not available for this architecture' 94 ssml_tags=[
"speak",
"ssml",
"phoneme",
"voice",
"audio",
"prosody"]
102 t = Thread(target=download_subscriber_voices, args=[self.
voice])
115 tag = tag.replace(key, value)
120 """ Build mimic arguments. """ 121 if (self.
voice in SUBSCRIBER_VOICES
and 124 mimic_bin = SUBSCRIBER_VOICES[self.
voice]
126 elif self.
voice in SUBSCRIBER_VOICES:
135 args = [mimic_bin,
'-voice', voice,
'-psdur',
'-ssml']
137 stretch = config.get(
'duration_stretch',
None)
139 args += [
'--setf',
'duration_stretch=' + stretch]
144 phonemes = subprocess.check_output(self.
args + [
'-o', wav_file,
146 return wav_file, phonemes.decode()
151 pairs = str(output).split(
" ")
153 pho_dur = pair.split(
":")
154 if len(pho_dur) == 2:
155 visemes.append((VISIMES.get(pho_dur[0],
'4'),
162 super(MimicValidator, self).
__init__(tts)
170 subprocess.call([BIN,
'--version'])
172 LOG.info(
"Failed to find mimic at: " + BIN)
174 'Mimic was not found. Run install-mimic.sh to install it.')
def validate_connection(self)
def download_subscriber_voices(selected_voice)
def download(url, dest, complete_action=None, header=None)
def __init__(self, lang, config)
def get(phrase, lang=None, context=None)
def modify_tag(self, tag)
def get_tts(self, sentence, wav_file)