async def process(self, text: str, lang: str) -> Union[str, PhonemeList]: """Beeps out parts of the text that are tagged with double asterisks. It basicaly replaces the opening and closing asterisk with two opening and closing 'stop words' then finds the phonemic form of these two and replaces the phonems inside with an equivalently long beep""" occ_list = re.findall(r"\*\*.+?\*\*", text) if occ_list: # replace the "**text**" by "king text gink" tagged_occ_list = [" king %s gink " % occ.strip("*") for occ in occ_list] for occ, tagged_occ in zip(occ_list, tagged_occ_list): text = text.replace(occ, tagged_occ) # getting the phonemic form of the text phonemes = await self.renderer.string_to_phonemes(text, lang, self.voice_params) # then using a simple state machine (in_beep is the state), replaces the phonems between # the right phonemic occurence with the phonems of a beep in_beep = False output, buffer = PhonemeList([]), PhonemeList([]) while phonemes: if PhonemeList(phonemes[:3]).phonemes_str == self._tags_phonems[lang][0] and not in_beep: in_beep, buffer = True, PhonemeList([]) phonemes = PhonemeList(phonemes[3:]) elif PhonemeList(phonemes[:4]).phonemes_str == self._tags_phonems[lang][1] and in_beep: in_beep = False # creating a beep of the buffer's duration if buffer: output += self._gen_beep(sum([pho.duration for pho in buffer]), lang) phonemes = phonemes[4:] elif not in_beep: output.append(phonemes.pop(0)) elif in_beep: buffer.append(phonemes.pop(0)) return output else: return text
def process(self, phonems: PhonemeList): silence = Phoneme("_", 61) reconstructed = PhonemeList([]) for i, phoneme in enumerate(phonems): if phonems[i].name in FrenchPhonemes.CONSONANTS \ and phonems[i + 1].name in FrenchPhonemes.VOWELS \ and random.randint(1, 3) == 1: reconstructed += [phonems[i], phonems[i + 1]] * 2 elif phoneme.name in FrenchPhonemes.VOWELS and random.randint(1, 3) == 1: reconstructed += [phoneme, silence, phoneme] else: reconstructed.append(phoneme) return reconstructed
def process(self, phonems: PhonemeList): reconstructed = PhonemeList([]) ng_phonem = Phoneme("N", 100) euh_phonem = Phoneme("2", 79) phonems.append(Phoneme("_", 10)) # end-silence-padding, just to be safe for i, phoneme in enumerate(phonems): if phoneme.name in FrenchPhonemes.NASAL_WOVELS: reconstructed += [phoneme, ng_phonem] elif phoneme.name in FrenchPhonemes.CONSONANTS - {"w"} and phonems[i + 1].name not in FrenchPhonemes.VOWELS: reconstructed += [phoneme, euh_phonem] elif phoneme.name == "o": phoneme.name = "O" reconstructed.append(phoneme) else: reconstructed.append(phoneme) return reconstructed
beat_duration = len(beats_track) / (rate * BEATS_TRACK_BEAT_COUNT) beats_track_looped = np.tile( beats_track, LOOPS_COUNT * BEATS_PER_MEASURE * len(CHORDS_PROGRESSION) // BEATS_TRACK_BEAT_COUNT) logging.info("Beat time : %dms" % (beat_duration * 1000)) logging.info("Measure time : %dms" % (beat_duration * 1000 * 4)) prog_freqs = get_trinote_progression_freqs(CHORDS_PROGRESSION) logging.info("First freq progression: \n %s" % (str(prog_freqs))) track_freqs = prog_freqs * LOOPS_COUNT progression_phonems = PhonemeList([]) for freq in track_freqs: progression_phonems.append( Phoneme("a", int(beat_duration * 1000), [(0, freq), (100, freq)])) logging.info("Rendering audio") voice = Voice(lang="fr", voice_id=2) wav = voice.to_audio(progression_phonems) if BEATS_TRACK_FILE is not None: rate, wave_array = to_f32_16k(wav) mixed_tracks = mix_tracks(beats_track_looped * 0.6, wave_array * 0.3, align="left") wav = to_wav_bytes(mixed_tracks, 16000) player = AudioPlayer() player.set_file(BytesIO(wav)) player.play() player.close()
beats_track_looped = np.tile(beats_track, PROG_LOOP_COUNT * BEATS_PER_MEASURE * FULL_LOOP_COUNT * \ (FIRST_PROG_REPEAT + SECOND_PROG_REPEAT) // BEATS_TRACK_BEAT_COUNT) logging.info("Beat time : %dms" % (beat_duration * 1000)) logging.info("Measure time : %dms" % (beat_duration * 1000 * 4)) first_prog_freqs = get_trinote_progression_freqs(FIRST_CHORDS_PROGRESSION) logging.info("First freq progression: \n %s" % (str(first_prog_freqs))) second_prog_freqs = get_trinote_progression_freqs(SECOND_CHORDS_PROGRESSION) logging.info("First freq progression: \n %s" % (str(second_prog_freqs))) track_freqs = first_prog_freqs * FIRST_PROG_REPEAT + second_prog_freqs * SECOND_PROG_REPEAT progression_phonems = PhonemeList([]) for freq in track_freqs * FULL_LOOP_COUNT: progression_phonems.append( Phoneme("w", int(beat_duration * 1000), [(0,freq), (100,freq)]) ) logging.info("Rendering audio") voice = Voice(lang="fr", voice_id=3) wav = voice.to_audio(progression_phonems) if BEATS_TRACK_FILE is not None: rate, wave_array = to_f32_16k(wav) mixed_tracks = mix_tracks(beats_track_looped * 0.6, wave_array * 0.4, align="left") wav = to_wav_bytes(mixed_tracks, 16000) player = AudioPlayer() player.set_file(BytesIO(wav)) player.play() player.close()