Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
| 3 |
import pyttsx3
|
| 4 |
-
import sounddevice as sd
|
| 5 |
-
import numpy as np
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
# Initialize the speech engine
|
| 9 |
engine = pyttsx3.init()
|
|
@@ -13,38 +10,24 @@ def speak(text):
|
|
| 13 |
engine.say(text)
|
| 14 |
engine.runAndWait()
|
| 15 |
|
| 16 |
-
# Function to listen to user voice input using
|
| 17 |
def listen():
|
| 18 |
recognizer = sr.Recognizer()
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
with sr.AudioData(audio_data, fs, 2) as source:
|
| 35 |
-
audio = recognizer.record(source)
|
| 36 |
-
|
| 37 |
-
print("Recognizing...")
|
| 38 |
-
try:
|
| 39 |
-
text = recognizer.recognize_google(audio)
|
| 40 |
-
print(f"Recognized text: {text}")
|
| 41 |
-
return text
|
| 42 |
-
except sr.UnknownValueError:
|
| 43 |
-
print("Sorry, I could not understand the audio.")
|
| 44 |
-
return None
|
| 45 |
-
except sr.RequestError:
|
| 46 |
-
print("Sorry, the speech recognition service is down.")
|
| 47 |
-
return None
|
| 48 |
|
| 49 |
# Define the function for Gradio interface
|
| 50 |
def voice_login():
|
|
@@ -69,3 +52,4 @@ iface = gr.Interface(fn=voice_login, inputs=[], outputs="text", live=True)
|
|
| 69 |
|
| 70 |
# Launch the interface
|
| 71 |
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
| 3 |
import pyttsx3
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize the speech engine
|
| 6 |
engine = pyttsx3.init()
|
|
|
|
| 10 |
engine.say(text)
|
| 11 |
engine.runAndWait()
|
| 12 |
|
| 13 |
+
# Function to listen to user voice input using SpeechRecognition
|
| 14 |
def listen():
|
| 15 |
recognizer = sr.Recognizer()
|
| 16 |
+
with sr.Microphone() as source:
|
| 17 |
+
print("Listening for your input...")
|
| 18 |
+
recognizer.adjust_for_ambient_noise(source)
|
| 19 |
+
audio = recognizer.listen(source)
|
| 20 |
+
print("Recognizing...")
|
| 21 |
+
try:
|
| 22 |
+
text = recognizer.recognize_google(audio)
|
| 23 |
+
print(f"Recognized text: {text}")
|
| 24 |
+
return text
|
| 25 |
+
except sr.UnknownValueError:
|
| 26 |
+
print("Sorry, I could not understand the audio.")
|
| 27 |
+
return None
|
| 28 |
+
except sr.RequestError:
|
| 29 |
+
print("Sorry, the speech recognition service is down.")
|
| 30 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Define the function for Gradio interface
|
| 33 |
def voice_login():
|
|
|
|
| 52 |
|
| 53 |
# Launch the interface
|
| 54 |
iface.launch()
|
| 55 |
+
|