17
17
18
18
# [START speech_transcribe_streaming_v2]
19
19
from 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
21
21
22
22
23
23
def transcribe_streaming_v2 (
24
24
project_id : str ,
25
25
audio_file : str ,
26
- ) -> cloud_speech .StreamingRecognizeResponse :
26
+ ) -> cloud_speech_types .StreamingRecognizeResponse :
27
27
"""Transcribes audio from audio file stream.
28
28
29
29
Args:
@@ -47,23 +47,23 @@ def transcribe_streaming_v2(
47
47
for start in range (0 , len (content ), chunk_length )
48
48
]
49
49
audio_requests = (
50
- cloud_speech .StreamingRecognizeRequest (audio = audio ) for audio in stream
50
+ cloud_speech_types .StreamingRecognizeRequest (audio = audio ) for audio in stream
51
51
)
52
52
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 (),
55
55
language_codes = ["en-US" ],
56
56
model = "long" ,
57
57
)
58
- streaming_config = cloud_speech .StreamingRecognitionConfig (
58
+ streaming_config = cloud_speech_types .StreamingRecognitionConfig (
59
59
config = recognition_config
60
60
)
61
- config_request = cloud_speech .StreamingRecognizeRequest (
61
+ config_request = cloud_speech_types .StreamingRecognizeRequest (
62
62
recognizer = f"projects/{ project_id } /locations/global/recognizers/_" ,
63
63
streaming_config = streaming_config ,
64
64
)
65
65
66
- def requests (config : cloud_speech .RecognitionConfig , audio : list ) -> list :
66
+ def requests (config : cloud_speech_types .RecognitionConfig , audio : list ) -> list :
67
67
yield config
68
68
yield from audio
69
69
0 commit comments