From c982eecbb7cd11500a59cc9221ce244574437af7 Mon Sep 17 00:00:00 2001 From: saleh alkhudairy Date: Fri, 30 Jan 2026 23:19:41 +0300 Subject: [PATCH] feat: add whisper and whisper API examples to audio_transcribe.py Adds examples for both local Whisper (recognize_whisper) and OpenAI Whisper API (recognize_openai) transcription to the audio_transcribe.py example file, matching the pattern already used in microphone_recognition.py. Closes #628 --- examples/audio_transcribe.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/audio_transcribe.py b/examples/audio_transcribe.py index f9836f0b..6b2e8468 100644 --- a/examples/audio_transcribe.py +++ b/examples/audio_transcribe.py @@ -11,6 +11,25 @@ r = sr.Recognizer() +# recognize speech using Whisper +try: + print("Whisper thinks you said " + r.recognize_whisper(audio, language="english")) +except sr.UnknownValueError: + print("Whisper could not understand audio") +except sr.RequestError as e: + print("Could not request results from Whisper; {0}".format(e)) + +# recognize speech using Whisper API +import os +OPENAI_API_KEY = "INSERT OPENAI API KEY HERE" +os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY +try: + print("Whisper API thinks you said " + r.recognize_openai(audio)) +except sr.UnknownValueError: + print("Whisper API could not understand audio") +except sr.RequestError as e: + print("Could not request results from Whisper API; {0}".format(e)) + # recognize speech using Sphinx try: print("Sphinx thinks you said " + r.recognize_sphinx(audio))