mails10 commited on
Commit
78dc3af
·
verified ·
1 Parent(s): e73342c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModel
3
+ import numpy as np
4
+ import soundfile as sf
5
+ import tempfile
6
+ import whisper
7
+
8
+ # Load TTS model (IndicF5)
9
+ tts_model = AutoModel.from_pretrained("ai4bharat/IndicF5", trust_remote_code=True)
10
+
11
+ # Load ASR model (Whisper)
12
+ asr_model = whisper.load_model("medium")
13
+
14
+ def generate_tts_and_transcribe(text, ref_audio, ref_text):
15
+ # Save uploaded ref_audio to a path
16
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
17
+ tmp.write(ref_audio.read())
18
+ ref_audio_path = tmp.name
19
+
20
+ # Generate speech using IndicF5
21
+ audio = tts_model(text, ref_audio_path=ref_audio_path, ref_text=ref_text)
22
+
23
+ # Normalize
24
+ if audio.dtype == np.int16:
25
+ audio = audio.astype(np.float32) / 32768.0
26
+
27
+ # Save TTS output
28
+ tts_path = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
29
+ sf.write(tts_path, np.array(audio, dtype=np.float32), samplerate=24000)
30
+
31
+ # Transcribe using Whisper
32
+ asr_result = asr_model.transcribe(tts_path, language="ta")
33
+ transcript = asr_result["text"]
34
+
35
+ return tts_path, transcript
36
+
37
+ # Gradio Interface
38
+ demo = gr.Interface(
39
+ fn=generate_tts_and_transcribe,
40
+ inputs=[
41
+ gr.Textbox(label="Text to Synthesize (Tamil)"),
42
+ gr.Audio(label="Reference Audio (.wav)", type="file"),
43
+ gr.Textbox(label="Reference Text (Tamil)")
44
+ ],
45
+ outputs=[
46
+ gr.Audio(label="Generated Audio", type="filepath"),
47
+ gr.Textbox(label="ASR Transcription (Whisper)")
48
+ ],
49
+ title="IndicF5 Tamil TTS + Whisper ASR",
50
+ description="Give a reference audio and text, synthesize Tamil speech using IndicF5, and transcribe it with Whisper."
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()