Skip to content

Commit

Permalink
[test] Cloud Speech-to-Text V1 parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Dec 21, 2024
1 parent 6477efa commit 9aa5504
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/recognizers/test_google_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,44 @@ def test_transcribe_show_all(SpeechClient, monkeypatch):
),
audio=RecognitionAudio(content=b"flac_data"),
)


@patch("google.cloud.speech.SpeechClient")
def test_transcribe_with_specified_api_parameters(SpeechClient, monkeypatch):
monkeypatch.setenv(
"GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json"
)

client = SpeechClient.return_value
client.recognize.return_value = RecognizeResponse(
results=[
SpeechRecognitionResult(
alternatives=[
SpeechRecognitionAlternative(
transcript="こんにちは", confidence=0.99
)
]
)
]
)

audio_data = MagicMock(spec=AudioData)
audio_data.sample_rate = 16_000
audio_data.get_flac_data.return_value = b"flac_data"

_ = recognize(
MagicMock(spec=Recognizer),
audio_data,
language="ja-JP",
use_enhanced=True,
)

client.recognize.assert_called_once_with(
config=RecognitionConfig(
encoding=RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=16_000,
language_code="ja-JP",
use_enhanced=True,
),
audio=RecognitionAudio(content=b"flac_data"),
)

0 comments on commit 9aa5504

Please sign in to comment.