Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
engine = pyttsx3.init()
|
| 7 |
def speak(text):
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
def recognize_speech():
|
| 13 |
-
recognizer = sr.Recognizer()
|
| 14 |
-
with sr.Microphone() as source:
|
| 15 |
-
print("Listening...")
|
| 16 |
-
try:
|
| 17 |
-
audio = recognizer.listen(source, timeout=5)
|
| 18 |
-
text = recognizer.recognize_google(audio)
|
| 19 |
-
print(f"You said: {text}")
|
| 20 |
-
return text
|
| 21 |
-
except sr.UnknownValueError:
|
| 22 |
-
return "I didn't catch that. Could you please repeat?"
|
| 23 |
-
except sr.RequestError:
|
| 24 |
-
return "Sorry, I'm having trouble understanding you. Please try again later."
|
| 25 |
-
|
| 26 |
-
# Voice Assistant Logic
|
| 27 |
def voice_assistant(user_input):
|
| 28 |
menu = {
|
| 29 |
"Bread": ["Roti", "Naan", "Paratha"],
|
|
@@ -31,7 +16,7 @@ def voice_assistant(user_input):
|
|
| 31 |
"Non-Veg Curries": ["Chicken Curry", "Mutton Curry", "Fish Curry"],
|
| 32 |
"Biryanis": ["Veg Biryani", "Chicken Biryani", "Mutton Biryani"]
|
| 33 |
}
|
| 34 |
-
|
| 35 |
if "menu" in user_input.lower() or "help" in user_input.lower():
|
| 36 |
response = (
|
| 37 |
"We have Bread, Veg Curries, Non-Veg Curries, and Biryanis. "
|
|
@@ -67,23 +52,18 @@ def voice_assistant(user_input):
|
|
| 67 |
return response
|
| 68 |
|
| 69 |
# Gradio UI
|
| 70 |
-
def interact_with_voice_assistant():
|
| 71 |
-
|
| 72 |
-
if user_input:
|
| 73 |
-
return voice_assistant(user_input)
|
| 74 |
-
else:
|
| 75 |
-
return "No input detected. Please try again."
|
| 76 |
|
| 77 |
iface = gr.Interface(
|
| 78 |
fn=interact_with_voice_assistant,
|
| 79 |
-
inputs=
|
| 80 |
outputs="text",
|
| 81 |
title="DynamicMenuApp Voice Assistant",
|
| 82 |
description=(
|
| 83 |
"Interact with the DynamicMenuApp Voice Assistant to navigate the menu, "
|
| 84 |
"customize your food, and place orders seamlessly."
|
| 85 |
-
)
|
| 86 |
-
live=True
|
| 87 |
)
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gtts import gTTS
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Text-to-Speech Function
|
|
|
|
| 6 |
def speak(text):
|
| 7 |
+
tts = gTTS(text=text, lang='en')
|
| 8 |
+
tts.save("output.mp3")
|
| 9 |
+
os.system("mpg123 output.mp3")
|
| 10 |
|
| 11 |
+
# Menu and Voice Assistant Logic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def voice_assistant(user_input):
|
| 13 |
menu = {
|
| 14 |
"Bread": ["Roti", "Naan", "Paratha"],
|
|
|
|
| 16 |
"Non-Veg Curries": ["Chicken Curry", "Mutton Curry", "Fish Curry"],
|
| 17 |
"Biryanis": ["Veg Biryani", "Chicken Biryani", "Mutton Biryani"]
|
| 18 |
}
|
| 19 |
+
|
| 20 |
if "menu" in user_input.lower() or "help" in user_input.lower():
|
| 21 |
response = (
|
| 22 |
"We have Bread, Veg Curries, Non-Veg Curries, and Biryanis. "
|
|
|
|
| 52 |
return response
|
| 53 |
|
| 54 |
# Gradio UI
|
| 55 |
+
def interact_with_voice_assistant(user_input):
|
| 56 |
+
return voice_assistant(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=interact_with_voice_assistant,
|
| 60 |
+
inputs="text",
|
| 61 |
outputs="text",
|
| 62 |
title="DynamicMenuApp Voice Assistant",
|
| 63 |
description=(
|
| 64 |
"Interact with the DynamicMenuApp Voice Assistant to navigate the menu, "
|
| 65 |
"customize your food, and place orders seamlessly."
|
| 66 |
+
)
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|