File size: 646 Bytes
1180f3c
67f0a18
 
 
1180f3c
b20a6cf
 
 
67f0a18
1180f3c
67f0a18
 
1180f3c
 
67f0a18
1180f3c
67f0a18
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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"