def _get_languages(self): 'Get all working voices and languages for eSpeak' def fix_voice(voice): 'Work-around bug in eSpeak 1.46 where gender is sometimes missing' if voice[2] not in ['M', 'F', '-']: return voice[:2] + ['-'] + voice[2:] # pragma: no cover return voice output = subprocess.check_output([self.ioptions['espeak'], '--voices'], universal_newlines=True) voices = [[ 'mbrola' if fix_voice(row.split())[4].startswith('mb') else 'espeak' ] + fix_voice(row.split())[:4] for row in output.split('\n')[1:] if row] if self.has_mbrola(): output = subprocess.check_output( [self.ioptions['espeak'], '--voices=mbrola'], universal_newlines=True) mvoices = [ fix_voice(row.split())[:5] for row in output.split('\n')[1:] if row ] for mvoice in mvoices: mbfile = mvoice[4].split('-')[1] mbfile = os.path.join(self.ioptions['mbrola_voices'], mbfile, mbfile) if os.path.isfile(mbfile): voices.append(['mbrola'] + mvoice) langs = set([voice[2].split('-')[0] for voice in voices]) if self.ioptions['passable_only']: langs = [lang for lang in langs if lang in self.QUALITY_LANGS] tree = dict([(lang, {'voices': {}}) for lang in langs]) for voice in voices: lang = voice[2].split('-')[0] if lang in langs: tree[lang]['voices'][voice[4]] = { 'gender': voice[3], 'pty': int(voice[1]), 'type': voice[0] } for lang in langs: # Try to find sane default voice, score by pty, then take shortest (for determinism) vcs = tree[lang]['voices'] pty = min([v['pty'] for v in vcs.values()]) tree[lang]['default'] = sorted( [k for k, v in vcs.items() if v['pty'] == pty])[0] return tree
def _get_options(self): output = subprocess.check_output( [self.ioptions['espeak'], '--voices=variant'], universal_newlines=True) variants = [ row[row.find('!v') + 3:].strip() for row in output.split('\n')[1:] if row ] return { 'variant': { 'type': 'enum', 'values': sorted([''] + variants), 'default': 'm3', }, 'pitch_adjustment': { 'type': 'int', 'min': 0, 'max': 99, 'default': 50, }, 'words_per_minute': { 'type': 'int', 'min': 80, 'max': 450, 'default': 150, }, }
def _is_available(self): if check_executable(self.ioptions['festival']): cmd = ['festival', '--pipe'] with tempfile.SpooledTemporaryFile() as in_f: self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) output = subprocess.check_output(cmd, stdin=in_f, stderr=subprocess.STDOUT, universal_newlines=True).strip() return 'No default voice found' not in output return False # pragma: no cover
def _get_languages(self): output = subprocess.check_output(['flite', '-lv'], universal_newlines=True) voices = output[output.find(':') + 1:].split() return { 'en': { 'default': 'kal', 'voices': dict([(voice, {}) for voice in voices]) } }
def _get_languages(self): 'Get all working voices and languages for eSpeak' def fix_voice(voice): 'Work-around bug in eSpeak 1.46 where gender is sometimes missing' if voice[2] not in ['M', 'F', '-']: return voice[:2] + ['-'] + voice[2:] # pragma: no cover return voice output = subprocess.check_output([self.ioptions['espeak'], '--voices'], universal_newlines=True) voices = [ ['mbrola' if fix_voice(row.split())[4].startswith('mb') else 'espeak'] + fix_voice(row.split())[:4] for row in output.split('\n')[1:] if row ] if self.has_mbrola(): output = subprocess.check_output([self.ioptions['espeak'], '--voices=mbrola'], universal_newlines=True) mvoices = [fix_voice(row.split())[:5] for row in output.split('\n')[1:] if row] for mvoice in mvoices: mbfile = mvoice[4].split('-')[1] mbfile = os.path.join(self.ioptions['mbrola_voices'], mbfile, mbfile) if os.path.isfile(mbfile): voices.append(['mbrola'] + mvoice) langs = set([voice[2].split('-')[0] for voice in voices]) if self.ioptions['passable_only']: langs = [lang for lang in langs if lang in self.QUALITY_LANGS] tree = dict([(lang, {'voices': {}}) for lang in langs]) for voice in voices: lang = voice[2].split('-')[0] if lang in langs: tree[lang]['voices'][voice[4]] = {'gender': voice[3], 'pty': int(voice[1]), 'type': voice[0]} for lang in langs: # Try to find sane default voice, score by pty, then take shortest (for determinism) vcs = tree[lang]['voices'] pty = min([v['pty'] for v in vcs.values()]) tree[lang]['default'] = sorted([k for k, v in vcs.items() if v['pty'] == pty])[0] return tree
def _is_available(self): if check_executable(self.ioptions['festival']): cmd = ['festival', '--pipe'] with tempfile.SpooledTemporaryFile() as in_f: self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) output = subprocess.check_output( cmd, stdin=in_f, stderr=subprocess.STDOUT, universal_newlines=True).strip() return 'No default voice found' not in output return False # pragma: no cover
def _get_languages(self): """ Parses the output of `say -v '?'` """ lines = subprocess.check_output([self.ioptions['say'], '-v', '?'], universal_newlines=True).split("\n") langs = {} for line in lines: voice = line.split() if len(voice) < 2: continue if voice[1][:2] not in langs: langs[voice[1][:2]] = {'default': voice[0], 'voices': {}} langs[voice[1][:2]]['voices'][voice[0]] = {} return langs
def _get_languages(self): """ Parses the output of `say -v '?'` """ lines = subprocess.check_output([self.ioptions['say'], '-v', '?'], universal_newlines=True).split("\n") langs = {} for line in lines: voice = line.split() if len(voice) < 2: continue if voice[1][:2] not in langs: langs[voice[1][:2]] = { 'default': voice[0], 'voices': { } } langs[voice[1][:2]]['voices'][voice[0]] = {} return langs
def _get_options(self): output = subprocess.check_output([self.ioptions['espeak'], '--voices=variant'], universal_newlines=True) variants = [row[row.find('!v') + 3:].strip() for row in output.split('\n')[1:] if row] return { 'variant': { 'type': 'enum', 'values': sorted([''] + variants), 'default': 'm3', }, 'pitch_adjustment': { 'type': 'int', 'min': 0, 'max': 99, 'default': 50, }, 'words_per_minute': { 'type': 'int', 'min': 80, 'max': 450, 'default': 150, }, }
def fakeplay(self, filename, translate=False): global LAST_PLAY output = subprocess.check_output(['file', filename], universal_newlines=True) LAST_PLAY = (self, filename, output)