NLPV commited on
Commit
ab2cf02
·
verified ·
1 Parent(s): a8f3ebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -38
app.py CHANGED
@@ -1,53 +1,32 @@
1
  import gradio as gr
2
- import os
3
  import tempfile
4
- from voice_cloning.generation import speech_generator, play_sound, save_sound
5
 
6
- def clone_voice(voice_sample, text, voice_type):
7
  """
8
- Clone a voice based on the provided reference audio and text.
9
- - voice_sample: the file path of the reference sound (supported formats: wav, etc.)
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
- # If needed, you could use a temporary file for the generated audio.
17
- # Here, we let the functions manage file names.
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
- # Return the file path so that Gradio can play the audio.
36
- return output_filename
 
 
 
37
 
38
- # Create the Gradio interface.
39
  iface = gr.Interface(
40
- fn=clone_voice,
41
  inputs=[
42
- gr.Audio(type="filepath", label="Reference Voice Sample"),
43
- gr.Textbox(lines=3, placeholder="Enter speech text here...", label="Speech Text"),
44
- gr.Dropdown(choices=["indian", "western"], value="western", label="Voice Type")
45
  ],
46
  outputs=gr.Audio(type="filepath", label="Generated Speech"),
47
- title="Voice Cloning TTS with Noise Reduction",
48
  description=(
49
- "Upload a reference voice sample and provide text to clone the voice and generate speech. "
50
- "Noise reduction is applied to the output."
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