-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #801 from ftnext/refactor/openai-whisper-api
Rename: recognize_whisper_api -> recognize_openai
- Loading branch information
Showing
8 changed files
with
70 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import httpx | ||
import respx | ||
|
||
from speech_recognition import AudioData, Recognizer | ||
from speech_recognition.recognizers import openai | ||
|
||
|
||
@respx.mock(assert_all_called=True, assert_all_mocked=True) | ||
def test_transcribe_with_openai_whisper(respx_mock, monkeypatch): | ||
monkeypatch.setenv("OPENAI_API_KEY", "sk_openai_api_key") | ||
|
||
respx_mock.post( | ||
"https://api.openai.com/v1/audio/transcriptions", | ||
headers__contains={"Authorization": "Bearer sk_openai_api_key"}, | ||
data__contains={"model": "whisper-1"}, | ||
).mock( | ||
return_value=httpx.Response( | ||
200, | ||
json={"text": "Transcription by OpenAI Whisper"}, | ||
) | ||
) | ||
|
||
audio_data = MagicMock(spec=AudioData) | ||
audio_data.get_wav_data.return_value = b"audio_data" | ||
|
||
actual = openai.recognize(MagicMock(spec=Recognizer), audio_data) | ||
|
||
assert actual == "Transcription by OpenAI Whisper" | ||
audio_data.get_wav_data.assert_called_once() |
This file was deleted.
Oops, something went wrong.