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)