File size: 1,407 Bytes
badff1c
 
 
 
 
b40d902
badff1c
 
 
 
 
 
 
b40d902
3363613
 
badff1c
 
 
 
b40d902
 
badff1c
 
 
 
3363613
badff1c
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import torch
from datasets import load_dataset
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
import soundfile as sf
import numpy as np

# Load the fine-tuned model, processor, and vocoder
model_name = "microsoft/speecht5_tts"
processor = SpeechT5Processor.from_pretrained(model_name)
model = SpeechT5ForTextToSpeech.from_pretrained("emirhanbilgic/speecht5_finetuned_emirhan_tr")
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

# Load speaker embeddings
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)

def text_to_speech(text):
    inputs = processor(text=text, return_tensors="pt")
    speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
    speech_numpy = speech.numpy()
    return (16000, speech_numpy)  # Return sample rate and numpy array

# Create Gradio interface
iface = gr.Interface(
    fn=text_to_speech,
    inputs=gr.Textbox(label="Enter Turkish text to convert to speech", value="Yapay zekayı seviyorum."),
    outputs=gr.Audio(label="Generated Speech"),
    title="Turkish SpeechT5 Text-to-Speech Demo",
    description="Enter Turkish text and listen to the generated speech using the fine-tuned SpeechT5 model."
)

# Launch the demo
iface.launch()