Skip to content

Commit

Permalink
Merge pull request #729 from herrjemand/herrjemand-oai-whisper-api-fix
Browse files Browse the repository at this point in the history
Updated to the latest OpenAI API changes, and fixed #720
  • Loading branch information
ftnext authored Mar 28, 2024
2 parents 1b737c5 + 9a694d7 commit 4a5b375
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions speech_recognition/recognizers/whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ def recognize_whisper_api(
wav_data = BytesIO(audio_data.get_wav_data())
wav_data.name = "SpeechRecognition_audio.wav"

transcript = openai.Audio.transcribe(model, wav_data, api_key=api_key)
return transcript["text"]
client = openai.OpenAI(api_key=api_key)
transcript = client.audio.transcriptions.create(file=wav_data, model=model)
return transcript.text
2 changes: 1 addition & 1 deletion tests/test_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_ibm_chinese(self):
def test_whisper_english(self):
r = sr.Recognizer()
with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source)
self.assertEqual(r.recognize_whisper(audio, language="english", **self.WHISPER_CONFIG), " 1, 2, 3.")
self.assertEqual(r.recognize_whisper(audio, language="english", **self.WHISPER_CONFIG), " 1, 2, 3")

def test_whisper_french(self):
r = sr.Recognizer()
Expand Down

0 comments on commit 4a5b375

Please sign in to comment.