Spaces:
Runtime error
Runtime error
pip install SpeechRecognition
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import speech_recognition as sr
|
| 2 |
+
|
| 3 |
+
def detect_voice(file_path):
|
| 4 |
+
recognizer = sr.Recognizer()
|
| 5 |
+
|
| 6 |
+
with sr.AudioFile(file_path) as source:
|
| 7 |
+
audio_data = recognizer.record(source) # Read the entire audio file
|
| 8 |
+
|
| 9 |
+
# Use the recognizer to transcribe the audio
|
| 10 |
+
try:
|
| 11 |
+
text = recognizer.recognize_google(audio_data)
|
| 12 |
+
return text
|
| 13 |
+
except sr.UnknownValueError:
|
| 14 |
+
return "Voice not recognized"
|
| 15 |
+
except sr.RequestError:
|
| 16 |
+
return "Could not request results; check your internet connection"
|
| 17 |
+
|
| 18 |
+
# Example usage:
|
| 19 |
+
file_path = "path_to_your_audio_file.mp4" # Update with your file path
|
| 20 |
+
result = detect_voice(file_path)
|
| 21 |
+
print("Detected voice:", result)
|