Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
import speech_recognition as sr
|
| 5 |
|
| 6 |
def transcribe_speech():
|
|
@@ -12,33 +10,29 @@ def transcribe_speech():
|
|
| 12 |
# Set the recording length (in seconds)
|
| 13 |
print("Listening...")
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
| 16 |
audio = r.listen(source)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Use Google's web-based speech-to-text algorithm to convert the audio to text
|
| 22 |
-
text = r.recognize_google(audio, language='en-US')
|
| 23 |
-
#print(f"The text you spoke was: {text}")
|
| 24 |
return text
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
except sr.RequestError as e:
|
| 30 |
-
print(f"Error; {e}")
|
| 31 |
-
|
| 32 |
-
else:
|
| 33 |
-
print("Speech pause is less than 1 second. Not transcribing.")
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
transcribe_speech
|
| 37 |
-
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
def greet(name):
|
| 41 |
return "Hello " + name + "!!"
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import speech_recognition as sr
|
| 3 |
|
| 4 |
def transcribe_speech():
|
|
|
|
| 10 |
# Set the recording length (in seconds)
|
| 11 |
print("Listening...")
|
| 12 |
|
| 13 |
+
# Adjust for ambient noise
|
| 14 |
+
r.adjust_for_ambient_noise(source)
|
| 15 |
+
|
| 16 |
+
# Record the sound
|
| 17 |
audio = r.listen(source)
|
| 18 |
|
| 19 |
+
try:
|
| 20 |
+
# Use Google's web-based speech-to-text algorithm to convert the audio to text
|
| 21 |
+
text = r.recognize_google(audio, language='en-US')
|
|
|
|
|
|
|
|
|
|
| 22 |
return text
|
| 23 |
|
| 24 |
+
except sr.UnknownValueError:
|
| 25 |
+
print("Sorry, I can't understand you.")
|
| 26 |
+
return "Sorry, I can't understand you."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
except sr.RequestError as e:
|
| 29 |
+
print(f"Error: {e}")
|
| 30 |
+
return f"Error: {e}"
|
| 31 |
|
| 32 |
+
# Define a simple greeting function for demonstration
|
| 33 |
def greet(name):
|
| 34 |
return "Hello " + name + "!!"
|
| 35 |
|
| 36 |
+
# Create a Gradio interface for the transcription function
|
| 37 |
+
demo = gr.Interface(fn=transcribe_speech, inputs="microphone", outputs="text")
|
| 38 |
demo.launch()
|