Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
| 4 |
-
import io
|
| 5 |
import speech_recognition as sr
|
| 6 |
|
| 7 |
# Menu for the restaurant
|
|
@@ -13,10 +12,10 @@ menu = {
|
|
| 13 |
}
|
| 14 |
|
| 15 |
# Text-to-Speech Function
|
| 16 |
-
def
|
| 17 |
tts = gTTS(text=text, lang='en')
|
| 18 |
-
tts.save(
|
| 19 |
-
|
| 20 |
|
| 21 |
# Speech Recognition Function
|
| 22 |
def recognize_speech(audio_file_path):
|
|
@@ -35,7 +34,7 @@ def recognize_speech(audio_file_path):
|
|
| 35 |
def process_order(audio_file_path):
|
| 36 |
user_input = recognize_speech(audio_file_path)
|
| 37 |
if user_input.startswith("Sorry") or user_input.startswith("I didn't"):
|
| 38 |
-
return user_input
|
| 39 |
|
| 40 |
response = f"You said: {user_input}\n"
|
| 41 |
|
|
@@ -49,14 +48,15 @@ def process_order(audio_file_path):
|
|
| 49 |
else:
|
| 50 |
response += "I'm not sure what you meant. Could you clarify?"
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
# Gradio Interface
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=process_order,
|
| 58 |
inputs=gr.Audio(type="filepath"), # Accept audio input as a file path
|
| 59 |
-
outputs="
|
| 60 |
title="Restaurant Voice Assistant",
|
| 61 |
description="Talk to our voice assistant to place your order or ask about the menu!"
|
| 62 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
|
|
|
| 4 |
import speech_recognition as sr
|
| 5 |
|
| 6 |
# Menu for the restaurant
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
# Text-to-Speech Function
|
| 15 |
+
def speak_and_save(text, filename="response.mp3"):
|
| 16 |
tts = gTTS(text=text, lang='en')
|
| 17 |
+
tts.save(filename)
|
| 18 |
+
return filename
|
| 19 |
|
| 20 |
# Speech Recognition Function
|
| 21 |
def recognize_speech(audio_file_path):
|
|
|
|
| 34 |
def process_order(audio_file_path):
|
| 35 |
user_input = recognize_speech(audio_file_path)
|
| 36 |
if user_input.startswith("Sorry") or user_input.startswith("I didn't"):
|
| 37 |
+
return user_input, None
|
| 38 |
|
| 39 |
response = f"You said: {user_input}\n"
|
| 40 |
|
|
|
|
| 48 |
else:
|
| 49 |
response += "I'm not sure what you meant. Could you clarify?"
|
| 50 |
|
| 51 |
+
# Generate audio response
|
| 52 |
+
audio_response_path = speak_and_save(response)
|
| 53 |
+
return response, audio_response_path
|
| 54 |
|
| 55 |
# Gradio Interface
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=process_order,
|
| 58 |
inputs=gr.Audio(type="filepath"), # Accept audio input as a file path
|
| 59 |
+
outputs=[gr.Textbox(label="Text Response"), gr.Audio(label="Audio Response")], # Include audio output
|
| 60 |
title="Restaurant Voice Assistant",
|
| 61 |
description="Talk to our voice assistant to place your order or ask about the menu!"
|
| 62 |
)
|