files added
Browse files- app.py +41 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from datasets import load_dataset
|
4 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
5 |
+
import soundfile as sf
|
6 |
+
|
7 |
+
# Load the fine-tuned model, processor, and vocoder
|
8 |
+
model_name = "microsoft/speecht5_tts"
|
9 |
+
processor = SpeechT5Processor.from_pretrained(model_name)
|
10 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("emirhanbilgic/speecht5_finetuned_emirhan_tr")
|
11 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
12 |
+
|
13 |
+
# Load the Turkish dataset
|
14 |
+
turkish_dataset = load_dataset("erenfazlioglu/turkishvoicedataset", split="train")
|
15 |
+
|
16 |
+
# Get an example text and its corresponding audio
|
17 |
+
example_item = turkish_dataset[0]
|
18 |
+
example_text = example_item['text']
|
19 |
+
example_audio = example_item['audio']['array']
|
20 |
+
|
21 |
+
# Create speaker embedding from the example audio
|
22 |
+
with torch.no_grad():
|
23 |
+
speaker_embeddings = model.get_speaker_embeddings(torch.tensor(example_audio).unsqueeze(0))
|
24 |
+
|
25 |
+
def text_to_speech(text):
|
26 |
+
inputs = processor(text=text, return_tensors="pt")
|
27 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
28 |
+
sf.write("output.wav", speech.numpy(), samplerate=16000)
|
29 |
+
return "output.wav"
|
30 |
+
|
31 |
+
# Create Gradio interface
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=text_to_speech,
|
34 |
+
inputs=gr.Textbox(label="Enter Turkish text to convert to speech", value=example_text),
|
35 |
+
outputs=gr.Audio(label="Generated Speech"),
|
36 |
+
title="Turkish SpeechT5 Text-to-Speech Demo",
|
37 |
+
description="Enter Turkish text and listen to the generated speech using the fine-tuned SpeechT5 model."
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the demo
|
41 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
datasets
|
3 |
+
soundfile
|
4 |
+
torch
|
5 |
+
torchaudio
|