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