metaambod / tts.py
unijoh's picture
Update tts.py
67f0a18 verified
raw
history blame
646 Bytes
import torch
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
from datasets import load_dataset
import soundfile as sf
MODEL_ID = "microsoft/speecht5_tts"
processor = SpeechT5Processor.from_pretrained(MODEL_ID)
model = SpeechT5ForTextToSpeech.from_pretrained(MODEL_ID)
vocoder = torch.hub.load("snakers4/silero-vad", "silero_vad", force_reload=True)
def synthesize_speech(text_input):
inputs = processor(text=text_input, return_tensors="pt")
with torch.no_grad():
speech = model.generate_speech(inputs["input_ids"], vocoder=vocoder)
sf.write("output.wav", speech.numpy(), 16000)
return "output.wav"