def version(): """Return version information for front and backends""" # version of the phonemizer _version = ( 'phonemizer-' + pkg_resources.get_distribution('phonemizer').version) # for each backend, check if it is available or not. If so get its version available = [] unavailable = [] if EspeakBackend.is_available(): available.append( 'espeak-' + ('ng-' if EspeakBackend.is_espeak_ng() else '') + _version_as_str(EspeakBackend.version())) else: # pragma: nocover unavailable.append('espeak') if EspeakMbrolaBackend.is_available(): available.append('espeak-mbrola') else: # pragma: nocover unavailable.append('espeak-mbrola') if FestivalBackend.is_available(): available.append( 'festival-' + _version_as_str(FestivalBackend.version())) else: # pragma: nocover unavailable.append('festival') if SegmentsBackend.is_available(): available.append( 'segments-' + _version_as_str(SegmentsBackend.version())) else: # pragma: nocover unavailable.append('segments') # resumes the backends status in the final version string if available: _version += '\navailable backends: ' + ', '.join(available) if unavailable: # pragma: nocover _version += '\nuninstalled backends: ' + ', '.join(unavailable) return _version
out = phonemize(' '.join(text), language='en-us', backend='espeak', strip=False, njobs=njobs) assert out == ' '.join(['wʌn tuː', 'θɹiː', 'foːɹ faɪv ']) out = phonemize(os.linesep.join(text), language='en-us', backend='espeak', strip=False, njobs=njobs) assert out == os.linesep.join(['wʌn tuː ', 'θɹiː ', 'foːɹ faɪv ']) @pytest.mark.skipif(not EspeakMbrolaBackend.is_available() or not EspeakMbrolaBackend.is_supported_language('mb-fr1'), reason='mbrola or mb-fr1 voice not installed') @pytest.mark.parametrize('njobs', [2, 4]) def test_espeak_mbrola(caplog, njobs): text = ['un deux', 'trois', 'quatre cinq'] out = phonemize(text, language='mb-fr1', backend='espeak-mbrola', njobs=njobs, preserve_punctuation=True) assert out == ['9~d2', 'tRwa', 'katRse~k'] messages = [msg[2] for msg in caplog.record_tuples] assert 'espeak-mbrola backend cannot preserve punctuation' in messages
with pytest.raises(RuntimeError): EspeakBackend.version() os.environ['PHONEMIZER_ESPEAK_PATH'] = __file__ with pytest.raises(ValueError): EspeakBackend.version() finally: try: del os.environ['PHONEMIZER_ESPEAK_PATH'] except KeyError: pass @pytest.mark.skipif( not EspeakMbrolaBackend.is_available() or not EspeakMbrolaBackend.is_supported_language('mb-fr1'), reason='mbrola or mb-fr1 voice not installed') @pytest.mark.parametrize( 'text, expected', [ # plosives ('pont', 'po~'), ('bon', 'bo~'), ('temps', 'ta~'), ('dans', 'da~'), ('quand', 'ka~'), ('gant', 'ga~'), # fricatives ('femme', 'fam'), ('vent', 'va~'),
def recognize(self, wav=None): if not self.eng.find("fest") == -1: # ======= festival english us only ===================================== from phonemizer.backend import FestivalBackend out1 = FestivalBackend( 'en-us', preserve_punctuation=False).phonemize(self.text, strip=True) elif not self.eng.find("esp") == -1: # ======= espeak ======================================================= from phonemizer.backend import EspeakBackend if not self.lan.find("en") == -1: backend = EspeakBackend('en-us') elif not self.lan.find("fr") == -1: backend = EspeakBackend('fr-fr') elif not self.lan.find("de") == -1 or not self.lan.find( "ger") == -1: backend = EspeakBackend('de-de') elif not self.lan.find("ita") == -1: backend = EspeakBackend('it-it') elif not self.lan.find("esp") == -1 or not self.lan.find( "spa") == -1: backend = EspeakBackend('es-es') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) elif not self.eng.find("mbr") == -1: # ====== mbrola ======================================================== from phonemizer.backend import EspeakBackend, EspeakMbrolaBackend if EspeakMbrolaBackend.is_available(): if not self.lan.find("en") == -1: EspeakMbrolaBackend('mb-en1') elif not self.lan.find("fr") == -1: EspeakMbrolaBackend('mb-fr2') elif not self.lan.find("de") == -1 or not self.lan.find( "ger") == -1: EspeakMbrolaBackend('mb-de1') elif not self.lan.find("ita") == -1: EspeakMbrolaBackend('mb-es1') elif not self.lan.find("esp") == -1 or not self.lan.find( "spa") == -1: EspeakMbrolaBackend('mb-it3') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) elif not self.eng.find("seg") == -1: # ===== segment ======================================================== from phonemizer.backend import SegmentsBackend if not self.lan.find("ja") == -1: backend = SegmentsBackend('japanese') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) else: print("Invalid Language specified") exit(1) print(out1) # return the result string to the speach engine