Spaces:
Build error
Build error
DSatishchandra
commited on
Commit
•
b782a3b
1
Parent(s):
50dadbc
Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,66 @@
|
|
1 |
-
import
|
2 |
from gtts import gTTS
|
3 |
import os
|
|
|
4 |
|
5 |
-
#
|
6 |
-
menu = {
|
7 |
-
"Appetizer": ["Veg Samosas", "Cut Mirchi", "Onion", "Spinach", "Mixed Vegetable"],
|
8 |
-
"Pakodas": ["Veg Pakoda", "Chicken Pakoda", "Fish Pakoda"],
|
9 |
-
"Manchurian": ["Vegetable", "Paneer", "Chicken", "Fish", "Jhinga"],
|
10 |
-
"Chilly": ["Gobi", "Paneer", "Chicken", "Fish", "Shrimp"],
|
11 |
-
"Chef's Special": ["Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Fish Fry"],
|
12 |
-
"Vegetarian Entree": ["Dal Fry", "Dal Makhani", "Channa Masala", "Aloo Gobi Masala", "Saag Paneer"],
|
13 |
-
"Chettinad": ["Egg", "Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Crab"],
|
14 |
-
"Butter Masala": ["Chicken", "Shrimp", "Gosht (Goat)"]
|
15 |
-
}
|
16 |
-
|
17 |
-
# Function to speak a text using Google Text-to-Speech (gTTS)
|
18 |
def speak(text):
|
19 |
tts = gTTS(text=text, lang='en')
|
20 |
tts.save("output.mp3")
|
21 |
-
#
|
22 |
-
# os.system("mpg321 output.mp3") #
|
23 |
|
24 |
-
# Function to
|
25 |
-
def
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
order = order.lower()
|
28 |
|
29 |
-
# Check for matching menu items
|
30 |
ordered_items = []
|
31 |
-
for
|
32 |
-
|
33 |
-
|
34 |
-
ordered_items.append(item)
|
35 |
|
36 |
if ordered_items:
|
37 |
-
response +=
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
else:
|
42 |
-
speak("Please tell me again what you'd like to order.")
|
43 |
-
return "Order not confirmed. Please try again."
|
44 |
else:
|
45 |
speak("Sorry, I couldn't find any items matching your order. Can you try again?")
|
46 |
-
return "Sorry, I couldn't find any items matching your order.
|
47 |
-
|
48 |
-
# Create Gradio interface
|
49 |
-
def start_assistant(order, confirmation):
|
50 |
-
return process_order(order, confirmation)
|
51 |
|
52 |
-
#
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
|
|
1 |
+
import speech_recognition as sr
|
2 |
from gtts import gTTS
|
3 |
import os
|
4 |
+
import time
|
5 |
|
6 |
+
# Function to speak using Google Text-to-Speech
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def speak(text):
|
8 |
tts = gTTS(text=text, lang='en')
|
9 |
tts.save("output.mp3")
|
10 |
+
os.system("start output.mp3") # For Windows
|
11 |
+
# os.system("mpg321 output.mp3") # Uncomment for Linux
|
12 |
|
13 |
+
# Function to listen and recognize speech using Google Speech Recognition
|
14 |
+
def listen():
|
15 |
+
recognizer = sr.Recognizer()
|
16 |
+
|
17 |
+
with sr.Microphone() as source:
|
18 |
+
print("Listening for your order...")
|
19 |
+
audio = recognizer.listen(source)
|
20 |
+
|
21 |
+
try:
|
22 |
+
# Using Google Speech Recognition to convert speech to text
|
23 |
+
order = recognizer.recognize_google(audio)
|
24 |
+
print(f"Recognized Order: {order}")
|
25 |
+
return order
|
26 |
+
except sr.UnknownValueError:
|
27 |
+
speak("Sorry, I could not understand that. Could you please repeat?")
|
28 |
+
return None
|
29 |
+
except sr.RequestError:
|
30 |
+
speak("Sorry, there was an issue with the service.")
|
31 |
+
return None
|
32 |
+
|
33 |
+
# Sample menu data
|
34 |
+
menu = ["Veg Samosas", "Chicken Pakoda", "Fish Fry", "Dal Fry", "Paneer Butter Masala"]
|
35 |
+
|
36 |
+
# Function to process the order
|
37 |
+
def process_order(order):
|
38 |
+
response = "You have ordered the following items: "
|
39 |
order = order.lower()
|
40 |
|
|
|
41 |
ordered_items = []
|
42 |
+
for item in menu:
|
43 |
+
if item.lower() in order:
|
44 |
+
ordered_items.append(item)
|
|
|
45 |
|
46 |
if ordered_items:
|
47 |
+
response += ", ".join(ordered_items) + ". Is that correct?"
|
48 |
+
speak(response)
|
49 |
+
time.sleep(2)
|
50 |
+
return response
|
|
|
|
|
|
|
51 |
else:
|
52 |
speak("Sorry, I couldn't find any items matching your order. Can you try again?")
|
53 |
+
return "Sorry, I couldn't find any items matching your order."
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
# Main function
|
56 |
+
def start_assistant():
|
57 |
+
speak("Welcome to the Voice Food Ordering Assistant!")
|
58 |
+
time.sleep(1)
|
59 |
+
speak("Please tell me what you would like to order.")
|
60 |
+
while True:
|
61 |
+
order = listen()
|
62 |
+
if order:
|
63 |
+
process_order(order)
|
64 |
|
65 |
+
if __name__ == "__main__":
|
66 |
+
start_assistant()
|