Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,83 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
| 3 |
-
from gtts import gTTS
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
tts = gTTS(text=text, lang='en')
|
| 9 |
-
# Save the speech to a temporary audio file
|
| 10 |
-
tts.save("output.mp3")
|
| 11 |
-
# Play the saved audio file (works locally with mpg321)
|
| 12 |
-
os.system("mpg321 output.mp3")
|
| 13 |
-
|
| 14 |
-
# Function to listen to user voice input using SpeechRecognition
|
| 15 |
-
def listen():
|
| 16 |
recognizer = sr.Recognizer()
|
|
|
|
|
|
|
| 17 |
with sr.Microphone() as source:
|
| 18 |
-
print("
|
| 19 |
recognizer.adjust_for_ambient_noise(source)
|
| 20 |
audio = recognizer.listen(source)
|
| 21 |
-
print("Recognizing...")
|
| 22 |
-
try:
|
| 23 |
-
text = recognizer.recognize_google(audio)
|
| 24 |
-
print(f"Recognized text: {text}")
|
| 25 |
-
return text
|
| 26 |
-
except sr.UnknownValueError:
|
| 27 |
-
print("Sorry, I could not understand the audio.")
|
| 28 |
-
return None
|
| 29 |
-
except sr.RequestError:
|
| 30 |
-
print("Sorry, the speech recognition service is down.")
|
| 31 |
-
return None
|
| 32 |
-
|
| 33 |
-
# Function to save HTML file temporarily
|
| 34 |
-
def save_html(name, gmail):
|
| 35 |
-
html_content = f"""
|
| 36 |
-
<!DOCTYPE html>
|
| 37 |
-
<html lang="en">
|
| 38 |
-
<head>
|
| 39 |
-
<meta charset="UTF-8">
|
| 40 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 41 |
-
<title>Briyani Hub Login</title>
|
| 42 |
-
</head>
|
| 43 |
-
<body>
|
| 44 |
-
<h1>Welcome to Briyani Hub</h1>
|
| 45 |
-
<p>Your Name: {name}</p>
|
| 46 |
-
<p>Your Gmail: {gmail}</p>
|
| 47 |
-
</body>
|
| 48 |
-
</html>
|
| 49 |
-
"""
|
| 50 |
-
# Save the HTML file temporarily in the current directory
|
| 51 |
-
file_name = "login_details.html"
|
| 52 |
-
with open(file_name, "w") as file:
|
| 53 |
-
file.write(html_content)
|
| 54 |
-
return file_name
|
| 55 |
-
|
| 56 |
-
# Define the function for Gradio interface
|
| 57 |
-
def voice_login():
|
| 58 |
-
speak("Welcome to Briyani Hub!")
|
| 59 |
-
speak("Please say your name.")
|
| 60 |
-
name = listen()
|
| 61 |
-
|
| 62 |
-
if name:
|
| 63 |
-
speak(f"You said your name is {name}.")
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
return file_path
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
iface = gr.Interface(fn=
|
| 79 |
inputs=[],
|
| 80 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
# Launch the interface
|
| 83 |
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def recognize_speech():
|
| 5 |
+
# Initialize recognizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
recognizer = sr.Recognizer()
|
| 7 |
+
|
| 8 |
+
# Microphone input
|
| 9 |
with sr.Microphone() as source:
|
| 10 |
+
print("Say something...")
|
| 11 |
recognizer.adjust_for_ambient_noise(source)
|
| 12 |
audio = recognizer.listen(source)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
try:
|
| 15 |
+
# Recognize speech using Google Web Speech API
|
| 16 |
+
text = recognizer.recognize_google(audio)
|
| 17 |
+
print("You said: " + text)
|
| 18 |
+
return text
|
| 19 |
+
except sr.UnknownValueError:
|
| 20 |
+
print("Sorry, I could not understand the audio.")
|
| 21 |
+
return "Sorry, I could not understand."
|
| 22 |
+
except sr.RequestError:
|
| 23 |
+
print("Could not request results from Google Speech Recognition service.")
|
| 24 |
+
return "Could not request results."
|
| 25 |
+
|
| 26 |
+
def voice_login_interface():
|
| 27 |
+
# Step 1: Welcome message
|
| 28 |
+
welcome_text = "Welcome to Briyani Hub."
|
| 29 |
|
| 30 |
+
# Step 2: Voice input for name
|
| 31 |
+
name_prompt = "Please enter your name letter by letter."
|
| 32 |
+
name_input = recognize_speech()
|
| 33 |
|
| 34 |
+
# Step 3: Voice input for Gmail
|
| 35 |
+
gmail_prompt = "Please enter your Gmail."
|
| 36 |
+
gmail_input = recognize_speech()
|
| 37 |
|
| 38 |
+
return f"{welcome_text}\n{name_prompt} {name_input}\n{gmail_prompt} {gmail_input}"
|
|
|
|
| 39 |
|
| 40 |
+
# Create the Gradio interface
|
| 41 |
+
iface = gr.Interface(fn=voice_login_interface,
|
| 42 |
inputs=[],
|
| 43 |
+
outputs="text",
|
| 44 |
+
live=True,
|
| 45 |
+
title="Briyani Hub Voice Login",
|
| 46 |
+
description="A voice-assisted login page for Briyani Hub")
|
| 47 |
|
|
|
|
| 48 |
iface.launch()
|
| 49 |
+
|