Spaces:
Paused
Paused
avinash
commited on
Commit
Β·
485d56c
1
Parent(s):
299633b
addedtts
Browse files
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
|
| 6 |
if audio is None:
|
| 7 |
-
return "No audio received!", "..."
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
ui = gr.Interface(
|
| 13 |
-
fn=
|
| 14 |
-
inputs=gr.Audio(type="filepath", label="Upload
|
| 15 |
outputs=[
|
| 16 |
gr.Textbox(label="π Transcribed Text"),
|
| 17 |
-
gr.Textbox(label="π€ LLM Reply")
|
|
|
|
| 18 |
],
|
| 19 |
-
title="VoiceFreight AI v1
|
| 20 |
-
description="Upload a voice file.
|
| 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
|