Spaces:
Runtime error
Runtime error
Download app.py from Alif737/Detect-Voices: direct link, hf CLI and curl.
- Browser
- Download file 725 Bytes
-
https://huggingface.co/spaces/Alif737/Detect-Voices/resolve/main/app.py
- Command line
-
hf download hf://spaces/Alif737/Detect-Voices/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Alif737/Detect-Voices/resolve/main/app.py
725 Bytes
| 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) | |