示例#1
0
def get_phonemes(utterance, lang="en", arpabet=True, default_dur=0.4):
    try:
        #raise
        from voxpopuli import Voice
        voice = Voice(lang=lang)
        print(voice.to_phonemes(utterance))
        if arpabet:

            return [(ipa2arpabet[phoneme.name.replace("_",
                                                      ".")], phoneme.duration)
                    for phoneme in voice.to_phonemes(utterance)]
        else:
            return [(phoneme.name.replace("_", "pau"), phoneme.duration)
                    for phoneme in voice.to_phonemes(utterance)]
    except:
        phones = fallback_get_phonemes(utterance, lang).split()
        # some cleanup, remove digits
        phones = [pho.strip("0123456789") for pho in phones]
        if not arpabet:
            phones = [arpabet2ipa[pho.replace(".", "_")] for pho in phones]
        return [(pho, default_dur) for pho in phones]
示例#2
0
文件: main.py 项目: hadware/katalixia
class RhymeTree(TreeNode):
    def __init__(self, rhyming_lang="fr"):
        super().__init__()
        self.voice = Voice(lang=rhyming_lang)
        self.children = dict()  # type:Dict[str,Union[TreeNode, Leaf]]

    def insert_rhyme(self, rhyme_string, data=None):
        new_leaf = Leaf.from_string(rhyme_string.strip(), self.voice)
        if new_leaf is not None:
            if data is not None:
                new_leaf.data = data
            self.insert(new_leaf, 1)
        else:
            logging.warning("Word '%s' returned empty phoneme" % rhyme_string)

    def find_rhyme(self, string):
        string_phonemes = Leaf.clean_silences(
            [pho.name for pho in self.voice.to_phonemes(string)])
        current_pho = string_phonemes.pop()
        if current_pho not in self.children:
            return None
        else:
            return self.children[current_pho].find(string_phonemes, string)

    def save(self, filepath):
        with open(filepath, "wb") as picklefile:
            pickle.dump(self, picklefile)

    @classmethod
    def from_pickle(cls, pickle_filepath):
        with open(pickle_filepath, "rb") as picklefile:
            return pickle.load(picklefile)

    @classmethod
    def from_text_file(cls, textfile_filepath, lang="fr", separator=None):
        separator = separator if separator is not None else "\n"
        with open(textfile_filepath) as file:
            all_strings = file.read().split(separator)

        return cls.from_word_list(all_strings, lang)

    @classmethod
    def from_word_list(cls, input_list, lang="fr"):
        tree = cls(lang)
        for string in input_list:
            tree.insert_rhyme(string)

        return tree

    def to_dict(self):
        return {pho: child.to_dict() for pho, child in self.children.items()}
示例#3
0
class TestEffects(unittest.TestCase):

    text = "Les écoute pas ces sheitane c  moi le vrai crysw"

    def setUp(self):
        self.effects = {
            eff_class: set()
            for eff_class in (PhonemicEffect, TextEffect, AudioEffect,
                              VoiceEffect)
        }
        for effect_cls in set(AVAILABLE_EFFECTS):
            effect = effect_cls()
            for cls in self.effects.keys():
                if isinstance(effect, cls):
                    self.effects[cls].add(effect)
        self.voice = Voice(lang="fr")

    def test_text_effects(self):
        for effect in self.effects[TextEffect]:
            self.assertIsNotNone(effect.process(self.text))

    def test_phonemic_effects(self):
        pho = self.voice.to_phonemes(self.text)
        for effect in self.effects[PhonemicEffect]:
            self.assertIsNotNone(effect.process(pho))

    def test_audio_effects(self):
        wav = self.voice.to_audio(self.text)
        _, wav_array = get_event_loop().run_until_complete(
            AudioRenderer.to_f32_16k(wav))
        for effect in self.effects[AudioEffect]:
            self.assertIsNotNone(effect.process(wav_array))

    def test_voice_effects(self):
        cookie_hash = md5(("parce que nous we").encode('utf8')).digest()
        voice_params = VoiceParameters.from_cookie_hash(cookie_hash)
        for effect in self.effects[VoiceEffect]:
            self.assertIsNotNone(effect.process(voice_params))
示例#4
0
import tqdm
import pprint

lx = pd.read_csv('data/lexique.csv', sep='\t')
filtered_lx = lx[lx['4_cgram'].isin(["NOM", "ADJ", "ADV"])]

dict_pho = {}

v = Voice(lang="fr")

for index, word_row in tqdm.tqdm(filtered_lx.iterrows(),
                                 total=len(filtered_lx)):
    mot = word_row["1_ortho"]

    try:
        phonemes = v.to_phonemes(mot)
    except Exception as e:
        print(e)
        print(mot)
        continue
    pho_list = []
    for pho in phonemes:
        if pho.name != "_":
            pho_list.append(pho.name)
    if len(pho_list) > 1:
        word_data = {
            "pho": pho_list,
            "gram": word_row["4_cgram"],
            "genre": word_row["5_genre"],
            "nb": word_row["6_nombre"],
        }
示例#5
0
文件: rimer.py 项目: juttingn/rimr
        elif pho in FrenchPhonemes.VOWELS:
            syllablebuffer.append(pho)
            syllabe = "".join(syllablebuffer)
            syllabe_list.append(syllabe)
            syllablebuffer = []
    #si le syllablebuffer n'est pas vide on ajoute les phonèmes à la dernière syllabe
    if syllablebuffer:
        syllabe_list[-1] += "".join(syllablebuffer)
    return syllabe_list


if __name__ == "__main__":
    args = parser.parse_args()

    v = Voice(lang="fr")
    phonemes = v.to_phonemes(args.query)

    pho_query = []
    for pho in phonemes:
        if pho.name != "_":
            pho_query.append(pho.name)

    rimes = []
    for mot, word_data in lexicon.items():
        pho_list = word_data['pho']

        # Depending on the argument selected by the user regarding grammatical class, genre, number,
        # certain words are 'skipped'.

        if args.gram is not None and word_data['gram'] not in args.gram:
            continue