Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def respond(audio_input):
|
| 5 |
user_input = transcribe_audio(audio_input)
|
| 6 |
text_response, output_path = generate_response(user_input)
|
|
@@ -23,7 +48,7 @@ input_audio = gr.Audio(
|
|
| 23 |
gr.Interface(
|
| 24 |
fn=respond,
|
| 25 |
inputs=input_audio,
|
| 26 |
-
outputs="text",
|
| 27 |
title="Tommy Vercetti Chatbot",
|
| 28 |
description="Chat with Tommy Vercetti from GTA Vice City. Get responses in both text and voice!"
|
| 29 |
).launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import speech_recognition as sr
|
| 3 |
+
from pydub import AudioSegment
|
| 4 |
|
| 5 |
+
# Function to transcribe audio to text
|
| 6 |
+
def transcribe_audio(audio_input):
|
| 7 |
+
recognizer = sr.Recognizer()
|
| 8 |
+
audio_file = sr.AudioFile(audio_input)
|
| 9 |
+
with audio_file as source:
|
| 10 |
+
audio_data = recognizer.record(source)
|
| 11 |
+
try:
|
| 12 |
+
text = recognizer.recognize_google(audio_data)
|
| 13 |
+
except sr.UnknownValueError:
|
| 14 |
+
text = "Sorry, I couldn't understand the audio."
|
| 15 |
+
except sr.RequestError:
|
| 16 |
+
text = "Sorry, there was a problem with the request."
|
| 17 |
+
return text
|
| 18 |
|
| 19 |
+
# Function to generate a response (you'll need to implement this)
|
| 20 |
+
def generate_response(user_input):
|
| 21 |
+
# Placeholder for the text response generation and TTS part
|
| 22 |
+
text_response = f"Responding as Tommy Vercetti: {user_input}"
|
| 23 |
+
# Generate audio path based on text_response
|
| 24 |
+
output_path = "response.wav" # Placeholder path
|
| 25 |
+
# Implement TTS and save to output_path
|
| 26 |
+
return text_response, output_path
|
| 27 |
+
|
| 28 |
+
# Function to process the audio input and return both text and audio response
|
| 29 |
def respond(audio_input):
|
| 30 |
user_input = transcribe_audio(audio_input)
|
| 31 |
text_response, output_path = generate_response(user_input)
|
|
|
|
| 48 |
gr.Interface(
|
| 49 |
fn=respond,
|
| 50 |
inputs=input_audio,
|
| 51 |
+
outputs=["text", "audio"],
|
| 52 |
title="Tommy Vercetti Chatbot",
|
| 53 |
description="Chat with Tommy Vercetti from GTA Vice City. Get responses in both text and voice!"
|
| 54 |
).launch(debug=True)
|