Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import speech_recognition as sr
|
| 3 |
+
import pyttsx3
|
| 4 |
+
|
| 5 |
+
# Initialize the speech engine
|
| 6 |
+
engine = pyttsx3.init()
|
| 7 |
+
|
| 8 |
+
# Function to speak text
|
| 9 |
+
def speak(text):
|
| 10 |
+
engine.say(text)
|
| 11 |
+
engine.runAndWait()
|
| 12 |
+
|
| 13 |
+
# Function to listen to user voice input
|
| 14 |
+
def listen():
|
| 15 |
+
recognizer = sr.Recognizer()
|
| 16 |
+
microphone = sr.Microphone()
|
| 17 |
+
|
| 18 |
+
with microphone as source:
|
| 19 |
+
print("Listening for your input...")
|
| 20 |
+
recognizer.adjust_for_ambient_noise(source)
|
| 21 |
+
audio = recognizer.listen(source)
|
| 22 |
+
print("Recognizing...")
|
| 23 |
+
try:
|
| 24 |
+
text = recognizer.recognize_google(audio)
|
| 25 |
+
print(f"Recognized text: {text}")
|
| 26 |
+
return text
|
| 27 |
+
except sr.UnknownValueError:
|
| 28 |
+
print("Sorry, I could not understand the audio.")
|
| 29 |
+
return None
|
| 30 |
+
except sr.RequestError:
|
| 31 |
+
print("Sorry, the speech recognition service is down.")
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
# Define the function for Gradio interface
|
| 35 |
+
def voice_login():
|
| 36 |
+
speak("Welcome to Briyani Hub!")
|
| 37 |
+
speak("Please say your name.")
|
| 38 |
+
name = listen()
|
| 39 |
+
|
| 40 |
+
if name:
|
| 41 |
+
speak(f"You said your name is {name}.")
|
| 42 |
+
|
| 43 |
+
speak("Please say your Gmail address.")
|
| 44 |
+
gmail = listen()
|
| 45 |
+
|
| 46 |
+
if gmail:
|
| 47 |
+
speak(f"You said your Gmail is {gmail}.")
|
| 48 |
+
|
| 49 |
+
# Return the captured data
|
| 50 |
+
return f"Name: {name}, Gmail: {gmail}"
|
| 51 |
+
|
| 52 |
+
# Define Gradio interface
|
| 53 |
+
iface = gr.Interface(fn=voice_login, inputs=[], outputs="text", live=True)
|
| 54 |
+
|
| 55 |
+
# Launch the interface
|
| 56 |
+
iface.launch()
|