1717
1818# [START speech_transcribe_streaming_v2]
1919from google .cloud .speech_v2 import SpeechClient
20- from google .cloud .speech_v2 .types import cloud_speech
20+ from google .cloud .speech_v2 .types import cloud_speech as cloud_speech_types
2121
2222
2323def transcribe_streaming_v2 (
2424 project_id : str ,
2525 audio_file : str ,
26- ) -> cloud_speech .StreamingRecognizeResponse :
26+ ) -> cloud_speech_types .StreamingRecognizeResponse :
2727 """Transcribes audio from audio file stream.
2828
2929 Args:
@@ -47,23 +47,23 @@ def transcribe_streaming_v2(
4747 for start in range (0 , len (content ), chunk_length )
4848 ]
4949 audio_requests = (
50- cloud_speech .StreamingRecognizeRequest (audio = audio ) for audio in stream
50+ cloud_speech_types .StreamingRecognizeRequest (audio = audio ) for audio in stream
5151 )
5252
53- recognition_config = cloud_speech .RecognitionConfig (
54- auto_decoding_config = cloud_speech .AutoDetectDecodingConfig (),
53+ recognition_config = cloud_speech_types .RecognitionConfig (
54+ auto_decoding_config = cloud_speech_types .AutoDetectDecodingConfig (),
5555 language_codes = ["en-US" ],
5656 model = "long" ,
5757 )
58- streaming_config = cloud_speech .StreamingRecognitionConfig (
58+ streaming_config = cloud_speech_types .StreamingRecognitionConfig (
5959 config = recognition_config
6060 )
61- config_request = cloud_speech .StreamingRecognizeRequest (
61+ config_request = cloud_speech_types .StreamingRecognizeRequest (
6262 recognizer = f"projects/{ project_id } /locations/global/recognizers/_" ,
6363 streaming_config = streaming_config ,
6464 )
6565
66- def requests (config : cloud_speech .RecognitionConfig , audio : list ) -> list :
66+ def requests (config : cloud_speech_types .RecognitionConfig , audio : list ) -> list :
6767 yield config
6868 yield from audio
6969
0 commit comments