geethareddy commited on
Commit
2303830
·
verified ·
1 Parent(s): 7accc7f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import speech_recognition as sr
2
+ import pyttsx3
3
+ import time
4
+
5
+ def speak(text):
6
+ engine = pyttsx3.init()
7
+ engine.say(text)
8
+ engine.runAndWait()
9
+
10
+ def get_voice_input(prompt, timeout=30):
11
+ recognizer = sr.Recognizer()
12
+ microphone = sr.Microphone()
13
+
14
+ speak(prompt)
15
+
16
+ with microphone as source:
17
+ print(prompt)
18
+ recognizer.adjust_for_ambient_noise(source)
19
+ try:
20
+ audio = recognizer.listen(source, timeout=timeout)
21
+ except sr.WaitTimeoutError:
22
+ speak("Time is up. Please try again.")
23
+ return get_voice_input(prompt, timeout)
24
+
25
+ try:
26
+ text = recognizer.recognize_google(audio)
27
+ print(f"Recognized: {text}")
28
+ return text
29
+ except sr.UnknownValueError:
30
+ speak("Sorry, I could not understand. Please repeat.")
31
+ return get_voice_input(prompt, timeout)
32
+ except sr.RequestError:
33
+ speak("Speech service is unavailable right now.")
34
+ return None
35
+
36
+ if __name__ == "__main__":
37
+ speak("Welcome to Biryani Hub")
38
+
39
+ username = get_voice_input("Please tell me your name. You have 30 seconds.", timeout=30)
40
+ if username:
41
+ speak(f"You said {username}. Now, please tell me your email address.")
42
+ email = get_voice_input("Please tell me your email address. You have 30 seconds.", timeout=30)
43
+ else:
44
+ speak("No response received for the name. Please try again later.")
45
+ exit()
46
+
47
+ if email:
48
+ with open("user_details.txt", "w") as file:
49
+ file.write(f"Username: {username}\n")
50
+ file.write(f"Email: {email}\n")
51
+
52
+ speak("Thank you! Your details have been recorded.")
53
+ else:
54
+ speak("No response received for the email. Please try again later.")