Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
# Import the Parler TTS package
|
| 3 |
+
from parler_tts import TTS
|
| 4 |
+
|
| 5 |
+
# Initialize the TTS model for Hindi with voice cloning capabilities.
|
| 6 |
+
# (Adjust the initialization parameters if needed.)
|
| 7 |
+
tts_model = TTS(language="hi")
|
| 8 |
+
|
| 9 |
+
def extract_speaker_embedding(voice_sample_path):
|
| 10 |
+
"""
|
| 11 |
+
Extract the speaker embedding from the provided voice sample.
|
| 12 |
+
This function assumes that the TTS model exposes an 'extract_embedding' method.
|
| 13 |
+
"""
|
| 14 |
+
# The extraction method below is pseudocode and might differ
|
| 15 |
+
# from the actual implementation in Parler TTS.
|
| 16 |
+
speaker_embedding = tts_model.extract_embedding(voice_sample_path)
|
| 17 |
+
return speaker_embedding
|
| 18 |
+
|
| 19 |
+
def synthesize_voice_with_cloning(voice_sample_path, hindi_text):
|
| 20 |
+
"""
|
| 21 |
+
Synthesize Hindi text into speech using voice cloning.
|
| 22 |
+
|
| 23 |
+
Steps:
|
| 24 |
+
1. Extract speaker embedding from the provided voice sample.
|
| 25 |
+
2. Synthesize speech from the input Hindi text conditioned on the extracted embedding.
|
| 26 |
+
"""
|
| 27 |
+
# Step 1: Get the speaker embedding from the voice sample.
|
| 28 |
+
speaker_embedding = extract_speaker_embedding(voice_sample_path)
|
| 29 |
+
|
| 30 |
+
# Step 2: Synthesize the speech using the extracted speaker embedding.
|
| 31 |
+
# The parameter 'speaker_embedding' might be named differently in the actual API.
|
| 32 |
+
audio_output = tts_model.synthesize(text=hindi_text, speaker_embedding=speaker_embedding)
|
| 33 |
+
return audio_output
|
| 34 |
+
|
| 35 |
+
# Build the Gradio interface for deployment
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=synthesize_voice_with_cloning,
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.Audio(source="upload", type="filepath", label="Upload Hindi Voice Sample"),
|
| 40 |
+
gr.Textbox(lines=3, placeholder="Enter Hindi text here...", label="Hindi Text")
|
| 41 |
+
],
|
| 42 |
+
outputs=gr.Audio(label="Generated Speech"),
|
| 43 |
+
title="Hindi TTS with Voice Cloning",
|
| 44 |
+
description="Upload a Hindi voice sample and enter Hindi text to generate cloned speech."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
iface.launch()
|