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 import StreamingRecognizeRequest
21+ from google .cloud .speech_v2 import RecognitionConfig
22+ from google .cloud .speech_v2 import StreamingRecognizeResponse
23+ from google .cloud .speech_v2 import StreamingRecognitionConfig
24+ from google .cloud .speech_v2 import AutoDetectDecodingConfig
2125
2226
2327def transcribe_streaming_v2 (
2428 project_id : str ,
2529 audio_file : str ,
26- ) -> cloud_speech . StreamingRecognizeResponse :
30+ ) -> StreamingRecognizeResponse :
2731 """Transcribes audio from audio file stream.
2832
2933 Args:
@@ -47,23 +51,23 @@ def transcribe_streaming_v2(
4751 for start in range (0 , len (content ), chunk_length )
4852 ]
4953 audio_requests = (
50- cloud_speech . StreamingRecognizeRequest (audio = audio ) for audio in stream
54+ StreamingRecognizeRequest (audio = audio ) for audio in stream
5155 )
5256
53- recognition_config = cloud_speech . RecognitionConfig (
54- auto_decoding_config = cloud_speech . AutoDetectDecodingConfig (),
57+ recognition_config = RecognitionConfig (
58+ auto_decoding_config = AutoDetectDecodingConfig (),
5559 language_codes = ["en-US" ],
5660 model = "long" ,
5761 )
58- streaming_config = cloud_speech . StreamingRecognitionConfig (
62+ streaming_config = StreamingRecognitionConfig (
5963 config = recognition_config
6064 )
61- config_request = cloud_speech . StreamingRecognizeRequest (
65+ config_request = StreamingRecognizeRequest (
6266 recognizer = f"projects/{ project_id } /locations/global/recognizers/_" ,
6367 streaming_config = streaming_config ,
6468 )
6569
66- def requests (config : cloud_speech . RecognitionConfig , audio : list ) -> list :
70+ def requests (config : RecognitionConfig , audio : list ) -> list :
6771 yield config
6872 yield from audio
6973
0 commit comments