Skip to content

Commit

Permalink
[docs] Tweak OpenAI example
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Dec 8, 2024
1 parent cd031eb commit 64fe533
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/microphone_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# NOTE: this example requires PyAudio because it uses the Microphone class

import os

import speech_recognition as sr

# obtain audio from the microphone
Expand Down Expand Up @@ -95,7 +97,8 @@

# recognize speech using Whisper API
OPENAI_API_KEY = "INSERT OPENAI API KEY HERE"
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
try:
print(f"Whisper API thinks you said {r.recognize_openai(audio, api_key=OPENAI_API_KEY)}")
print(f"OpenAI Whisper API thinks you said {r.recognize_openai(audio)}")
except sr.RequestError as e:
print(f"Could not request results from Whisper API; {e}")
print(f"Could not request results from OpenAI Whisper API; {e}")

0 comments on commit 64fe533

Please sign in to comment.