Skip to content

Commit

Permalink
fix: update speech imports (#11278)
Browse files Browse the repository at this point in the history
* created a new branch for import issue

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
jping0220 and gcf-owl-bot[bot] authored Mar 20, 2024
1 parent 217d590 commit 1be81b3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions speech/snippets/beta_snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_transcribe_multichannel_file(capsys: pytest.CaptureFixture) -> None:
result = transcribe_file_with_multichannel()
out, err = capsys.readouterr()

assert "OK Google stream stranger things from Netflix to my TV" in out
assert "Okay Google stream stranger things from Netflix to my TV" in out
assert result is not None


Expand All @@ -93,7 +93,7 @@ def test_transcribe_word_level_confidence(capsys: pytest.CaptureFixture) -> None
result = transcribe_file_with_word_level_confidence()
out, err = capsys.readouterr()

assert "OK Google stream stranger things from Netflix to my TV" in out
assert "Okay Google stream stranger things from Netflix to my TV" in out
assert result is not None


Expand Down
5 changes: 1 addition & 4 deletions speech/snippets/transcribe_batch_multiple_files_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def transcribe_batch_multiple_files_v2(
model="long",
)

files = [
cloud_speech.BatchRecognizeFileMetadata(uri=uri)
for uri in gcs_uris
]
files = [cloud_speech.BatchRecognizeFileMetadata(uri=uri) for uri in gcs_uris]

request = cloud_speech.BatchRecognizeRequest(
recognizer=f"projects/{project_id}/locations/global/recognizers/_",
Expand Down
1 change: 1 addition & 0 deletions speech/snippets/transcribe_chirp_auto_detect_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def transcribe_chirp_auto_detect_language(

return response


# [END speech_transcribe_chirp_auto_detect_language]


Expand Down
8 changes: 5 additions & 3 deletions speech/snippets/transcribe_chirp_auto_detect_language_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
def test_transcribe_chirp() -> None:
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")

response = transcribe_chirp_auto_detect_language.transcribe_chirp_auto_detect_language(
project_id, os.path.join(_RESOURCES, "audio.wav")
response = (
transcribe_chirp_auto_detect_language.transcribe_chirp_auto_detect_language(
project_id, os.path.join(_RESOURCES, "audio.wav")
)
)

assert re.search(
Expand All @@ -36,4 +38,4 @@ def test_transcribe_chirp() -> None:
re.DOTALL | re.I,
)

assert response.results[0].language_code == 'en'
assert response.results[0].language_code == "en"
16 changes: 8 additions & 8 deletions speech/snippets/transcribe_streaming_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

# [START speech_transcribe_streaming_v2]
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.cloud.speech_v2.types import cloud_speech as cloud_speech_types


def transcribe_streaming_v2(
project_id: str,
audio_file: str,
) -> cloud_speech.StreamingRecognizeResponse:
) -> cloud_speech_types.StreamingRecognizeResponse:
"""Transcribes audio from audio file stream.
Args:
Expand All @@ -47,23 +47,23 @@ def transcribe_streaming_v2(
for start in range(0, len(content), chunk_length)
]
audio_requests = (
cloud_speech.StreamingRecognizeRequest(audio=audio) for audio in stream
cloud_speech_types.StreamingRecognizeRequest(audio=audio) for audio in stream
)

recognition_config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
recognition_config = cloud_speech_types.RecognitionConfig(
auto_decoding_config=cloud_speech_types.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="long",
)
streaming_config = cloud_speech.StreamingRecognitionConfig(
streaming_config = cloud_speech_types.StreamingRecognitionConfig(
config=recognition_config
)
config_request = cloud_speech.StreamingRecognizeRequest(
config_request = cloud_speech_types.StreamingRecognizeRequest(
recognizer=f"projects/{project_id}/locations/global/recognizers/_",
streaming_config=streaming_config,
)

def requests(config: cloud_speech.RecognitionConfig, audio: list) -> list:
def requests(config: cloud_speech_types.RecognitionConfig, audio: list) -> list:
yield config
yield from audio

Expand Down

0 comments on commit 1be81b3

Please sign in to comment.