Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import SpeechT5ForTextToSpeech, SpeechT5Processor, SpeechT5HifiGan
|
4 |
+
import soundfile as sf
|
5 |
+
|
6 |
+
|
7 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("Beehzod/speecht5_finetuned_uz_customData2")
|
8 |
+
processor = SpeechT5Processor.from_pretrained("Beehzod/speecht5_finetuned_uz_customData2")
|
9 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
10 |
+
|
11 |
+
speaker_embeddings = torch.zeros((1, 512))
|
12 |
+
|
13 |
+
def text_to_speech(text):
|
14 |
+
|
15 |
+
inputs = processor(text=text, return_tensors="pt")
|
16 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
17 |
+
output_path = "output.wav"
|
18 |
+
sf.write(output_path, speech.numpy(), 16000)
|
19 |
+
return output_path
|
20 |
+
|
21 |
+
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=text_to_speech,
|
24 |
+
inputs="text",
|
25 |
+
outputs="audio",
|
26 |
+
title="Uzbek Text-to-Speech Generator",
|
27 |
+
description="Enter Uzbek text and generate speech using the finetuned SpeechT5 model."
|
28 |
+
)
|
29 |
+
|
30 |
+
interface.launch()
|