import gradio as gr import librosa import numpy as np import torch import pyewts import noisereduce as nr from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan def remove_repeated_words(text): # Tokenize the input text into words words = text.split() # Create a dictionary to count word occurrences word_count = {} # Create a list to store the final words new_words = [] for word in words: # Check if the word is in the dictionary if word in word_count: # If it has occurred once before, add it to the list with a count of 2 if word_count[word] == 1: new_words.append(word) word_count[word] = 2 else: # If it has not occurred before, add it to the dictionary with a count of 1 word_count[word] = 1 new_words.append(word) # Join the modified words back into a string result = ' '.join(new_words) return result converter = pyewts.pyewts() checkpoint = "TenzinGayche/TTS_run3_ep20_174k_b" processor = SpeechT5Processor.from_pretrained(checkpoint) model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint) model.to('cuda') vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan") speaker_embeddings = { "Lhasa(female)": "female_2.npy", } replacements = [ ('_', '_'), ('*', 'v'), ('`', ';'), ('~', ','), ('+', ','), ('\\', ';'), ('|', ';'), ('╚',''), ('╗','') ] def cleanup_text(inputs): for src, dst in replacements: inputs = inputs.replace(src, dst) return inputs def predict(text, speaker): if len(text.strip()) == 0: return (16000, np.zeros(0).astype(np.int16)) text = converter.toWylie(text) text=cleanup_text(text) inputs = processor(text=text, return_tensors="pt") # limit input length input_ids = inputs["input_ids"] input_ids = input_ids[..., :model.config.max_text_positions] speaker_embedding = np.load(speaker_embeddings[speaker]) speaker_embedding = torch.tensor(speaker_embedding) speech = model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=vocoder.to('cuda')) speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000) return (16000, speech) title = "Tibetan TTS" description = """ The SpeechT5 model is pre-trained on text as well as speech inputs, with targets that are also a mix of text and speech. By pre-training on text and speech at the same time, it learns unified representations for both, resulting in improved modeling capabilities. """ article = """
References: SpeechT5 paper | original GitHub | original weights
@article{Ao2021SpeechT5, title = {SpeechT5: Unified-Modal Encoder-Decoder Pre-training for Spoken Language Processing}, author = {Junyi Ao and Rui Wang and Long Zhou and Chengyi Wang and Shuo Ren and Yu Wu and Shujie Liu and Tom Ko and Qing Li and Yu Zhang and Zhihua Wei and Yao Qian and Jinyu Li and Furu Wei}, eprint={2110.07205}, archivePrefix={arXiv}, primaryClass={eess.AS}, year={2021} }
Speaker embeddings were generated from CMU ARCTIC using this script.