avinash commited on
Commit
485d56c
Β·
1 Parent(s): 299633b
Files changed (2) hide show
  1. app.py +20 -10
  2. tts.py +8 -0
app.py CHANGED
@@ -1,23 +1,33 @@
1
  import gradio as gr
2
  from asr import transcribe_audio
3
  from llm_agent import get_llm_reply
 
4
 
5
- def voice_to_reply(audio):
6
  if audio is None:
7
- return "No audio received!", "..."
8
- text = transcribe_audio(audio)
9
- reply = get_llm_reply(text)
10
- return text, reply
 
 
 
 
 
 
 
 
11
 
12
  ui = gr.Interface(
13
- fn=voice_to_reply,
14
- inputs=gr.Audio(type="filepath", label="Upload voice (.wav or .mp3)"),
15
  outputs=[
16
  gr.Textbox(label="πŸ“ Transcribed Text"),
17
- gr.Textbox(label="πŸ€– LLM Reply")
 
18
  ],
19
- title="VoiceFreight AI v1: ASR + LLM",
20
- description="Upload a voice file. ASR + TinyLlama gives you a response!"
21
  )
22
 
23
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from asr import transcribe_audio
3
  from llm_agent import get_llm_reply
4
+ from tts import generate_speech
5
 
6
+ def voice_agent(audio):
7
  if audio is None:
8
+ return "No audio received!", "...", None
9
+
10
+ # ASR
11
+ user_text = transcribe_audio(audio)
12
+
13
+ # LLM
14
+ bot_reply = get_llm_reply(user_text)
15
+
16
+ # TTS
17
+ audio_reply = generate_speech(bot_reply)
18
+
19
+ return user_text, bot_reply, audio_reply
20
 
21
  ui = gr.Interface(
22
+ fn=voice_agent,
23
+ inputs=gr.Audio(type="filepath", label="πŸŽ™οΈ Upload Voice (.wav or .mp3)"),
24
  outputs=[
25
  gr.Textbox(label="πŸ“ Transcribed Text"),
26
+ gr.Textbox(label="πŸ€– LLM Reply"),
27
+ gr.Audio(type="filepath", label="πŸ”Š AI Voice Response")
28
  ],
29
+ title="VoiceFreight AI v1.0",
30
+ description="Upload a voice file. Get a spoken reply from an AI freight agent!"
31
  )
32
 
33
  if __name__ == "__main__":
tts.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from TTS.api import TTS
2
+
3
+
4
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
5
+
6
+ def generate_speech(text, filename="output.wav"):
7
+ tts.tts_to_file(text=text, file_path=filename)
8
+ return filename