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