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