Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import tempfile
|
| 4 |
-
from voice_cloning.generation import speech_generator, play_sound, save_sound
|
| 5 |
|
| 6 |
-
def
|
| 7 |
"""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
- text: the speech text to synthesize
|
| 11 |
-
- voice_type: a string to choose between "indian" or "western"
|
| 12 |
-
|
| 13 |
-
The function uses the speech_generator to create the audio, applies noise reduction,
|
| 14 |
-
and returns the saved file path.
|
| 15 |
"""
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
generated_wav = speech_generator(
|
| 19 |
-
voice_type=voice_type,
|
| 20 |
-
sound_path=voice_sample,
|
| 21 |
-
speech_text=text
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
# Optionally play the sound (for local testing, not used by Gradio)
|
| 25 |
-
# play_sound(generated_wav)
|
| 26 |
-
|
| 27 |
-
# Save the output with noise reduction enabled.
|
| 28 |
-
# The save_sound function is expected to save the file with the given filename.
|
| 29 |
-
# We'll use a temporary directory to store the output.
|
| 30 |
-
temp_dir = tempfile.gettempdir()
|
| 31 |
-
output_filename = os.path.join(temp_dir, "voice_output.wav")
|
| 32 |
-
|
| 33 |
-
save_sound(generated_wav, filename=output_filename, noise_reduction=True)
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
# Create the Gradio interface.
|
| 39 |
iface = gr.Interface(
|
| 40 |
-
fn=
|
| 41 |
inputs=[
|
| 42 |
-
gr.
|
| 43 |
-
gr.
|
| 44 |
-
gr.Dropdown(choices=["indian", "western"], value="western", label="Voice Type")
|
| 45 |
],
|
| 46 |
outputs=gr.Audio(type="filepath", label="Generated Speech"),
|
| 47 |
-
title="
|
| 48 |
description=(
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
)
|
| 52 |
)
|
| 53 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gtts import gTTS
|
| 3 |
import tempfile
|
|
|
|
| 4 |
|
| 5 |
+
def text_to_speech(text, voice_sample=None):
|
| 6 |
"""
|
| 7 |
+
Generate Hindi speech from input text using gTTS.
|
| 8 |
+
Note: The voice_sample is accepted but not used, since voice cloning for Hindi is not supported.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
+
# Generate Hindi speech using gTTS (lang='hi')
|
| 11 |
+
tts = gTTS(text=text, lang='hi')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Save to a temporary MP3 file
|
| 14 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
|
| 15 |
+
tts.save(fp.name)
|
| 16 |
+
audio_file = fp.name
|
| 17 |
+
return audio_file
|
| 18 |
|
|
|
|
| 19 |
iface = gr.Interface(
|
| 20 |
+
fn=text_to_speech,
|
| 21 |
inputs=[
|
| 22 |
+
gr.Textbox(lines=5, placeholder="हिंदी में टेक्स्ट दर्ज करें...", label="Text"),
|
| 23 |
+
gr.Audio(type="filepath", label="Voice Sample (ignored)")
|
|
|
|
| 24 |
],
|
| 25 |
outputs=gr.Audio(type="filepath", label="Generated Speech"),
|
| 26 |
+
title="Hindi Text-to-Speech",
|
| 27 |
description=(
|
| 28 |
+
"Generate Hindi speech from text using gTTS. Note: "
|
| 29 |
+
"Voice cloning is not available for Hindi; the voice sample input is ignored."
|
| 30 |
)
|
| 31 |
)
|
| 32 |
|