Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,10 @@ def speak(text):
|
|
| 19 |
os.system("play response.mp3 || mpg123 response.mp3")
|
| 20 |
|
| 21 |
# Speech Recognition Function
|
| 22 |
-
def recognize_speech(
|
| 23 |
recognizer = sr.Recognizer()
|
| 24 |
try:
|
| 25 |
-
with sr.AudioFile(
|
| 26 |
audio_data = recognizer.record(source)
|
| 27 |
text = recognizer.recognize_google(audio_data)
|
| 28 |
return text
|
|
@@ -32,12 +32,8 @@ def recognize_speech(audio):
|
|
| 32 |
return "There was an issue processing your speech. Try again later."
|
| 33 |
|
| 34 |
# Voice Assistant Logic
|
| 35 |
-
def process_order(
|
| 36 |
-
|
| 37 |
-
temp_audio = io.BytesIO(audio)
|
| 38 |
-
temp_audio.seek(0)
|
| 39 |
-
|
| 40 |
-
user_input = recognize_speech(temp_audio)
|
| 41 |
if user_input.startswith("Sorry") or user_input.startswith("I didn't"):
|
| 42 |
return user_input
|
| 43 |
|
|
@@ -59,7 +55,7 @@ def process_order(audio):
|
|
| 59 |
# Gradio Interface
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=process_order,
|
| 62 |
-
inputs=gr.Audio(
|
| 63 |
outputs="text",
|
| 64 |
title="Restaurant Voice Assistant",
|
| 65 |
description="Talk to our voice assistant to place your order or ask about the menu!"
|
|
|
|
| 19 |
os.system("play response.mp3 || mpg123 response.mp3")
|
| 20 |
|
| 21 |
# Speech Recognition Function
|
| 22 |
+
def recognize_speech(audio_file_path):
|
| 23 |
recognizer = sr.Recognizer()
|
| 24 |
try:
|
| 25 |
+
with sr.AudioFile(audio_file_path) as source:
|
| 26 |
audio_data = recognizer.record(source)
|
| 27 |
text = recognizer.recognize_google(audio_data)
|
| 28 |
return text
|
|
|
|
| 32 |
return "There was an issue processing your speech. Try again later."
|
| 33 |
|
| 34 |
# Voice Assistant Logic
|
| 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 |
|
|
|
|
| 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="text",
|
| 60 |
title="Restaurant Voice Assistant",
|
| 61 |
description="Talk to our voice assistant to place your order or ask about the menu!"
|