|
29 | 29 |
|
30 | 30 | import asyncio |
31 | 31 | from collections.abc import AsyncIterable |
32 | | -import dataclasses |
33 | 32 | import time |
34 | 33 |
|
35 | 34 | from absl import logging |
36 | | -import dataclasses_json |
37 | 35 | from genai_processors import content_api |
38 | 36 | from genai_processors import processor |
39 | 37 | from genai_processors import streams |
| 38 | +from genai_processors.core import speech_events |
40 | 39 | from google.cloud import speech_v2 |
41 | 40 | import grpc |
42 | 41 |
|
|
63 | 62 | ProcessorPart = content_api.ProcessorPart |
64 | 63 | ProcessorPartTypes = content_api.ProcessorPartTypes |
65 | 64 |
|
66 | | -TRANSCRIPTION_SUBSTREAM_NAME = 'input_transcription' |
67 | | -ENDPOINTING_SUBSTREAM_NAME = 'input_endpointing' |
68 | | - |
69 | | - |
70 | | -@dataclasses_json.dataclass_json |
71 | | -@dataclasses.dataclass(frozen=True) |
72 | | -class StartOfSpeech: |
73 | | - """Start of speech event.""" |
74 | | - |
75 | | - pass |
76 | | - |
77 | | - |
78 | | -@dataclasses_json.dataclass_json |
79 | | -@dataclasses.dataclass(frozen=True) |
80 | | -class EndOfSpeech: |
81 | | - """End of speech event.""" |
82 | | - |
83 | | - pass |
| 65 | +# Re-export from speech_events for backward compatibility. |
| 66 | +# Use speech_events variants instead. |
| 67 | +StartOfSpeech = speech_events.StartOfSpeech |
| 68 | +EndOfSpeech = speech_events.EndOfSpeech |
| 69 | +TRANSCRIPTION_SUBSTREAM_NAME = speech_events.TRANSCRIPTION_SUBSTREAM_NAME |
| 70 | +ENDPOINTING_SUBSTREAM_NAME = speech_events.ENDPOINTING_SUBSTREAM_NAME |
84 | 71 |
|
85 | 72 |
|
86 | 73 | class AddSilentPartMaybe(processor.Processor): |
@@ -139,10 +126,10 @@ def __init__( |
139 | 126 | project_id: str, |
140 | 127 | recognition_config: speech_v2.types.RecognitionConfig, |
141 | 128 | with_endpointing: bool = True, |
142 | | - substream_endpointing: str = ENDPOINTING_SUBSTREAM_NAME, |
| 129 | + substream_endpointing: str = speech_events.ENDPOINTING_SUBSTREAM_NAME, |
143 | 130 | strict_endpointing: bool = True, |
144 | 131 | with_interim_results: bool = True, |
145 | | - substream_transcription: str = TRANSCRIPTION_SUBSTREAM_NAME, |
| 132 | + substream_transcription: str = speech_events.TRANSCRIPTION_SUBSTREAM_NAME, |
146 | 133 | passthrough_audio: bool = False, |
147 | 134 | ): |
148 | 135 | """Transcribes audio parts using the Cloud Speech API. |
@@ -350,10 +337,10 @@ def __init__( |
350 | 337 | recognition_config: speech_v2.types.RecognitionConfig | None = None, |
351 | 338 | audio_passthrough: bool = False, |
352 | 339 | with_endpointing: bool = True, |
353 | | - substream_endpointing: str = ENDPOINTING_SUBSTREAM_NAME, |
| 340 | + substream_endpointing: str = speech_events.ENDPOINTING_SUBSTREAM_NAME, |
354 | 341 | strict_endpointing: bool = True, |
355 | 342 | with_interim_results: bool = True, |
356 | | - substream_transcription: str = TRANSCRIPTION_SUBSTREAM_NAME, |
| 343 | + substream_transcription: str = speech_events.TRANSCRIPTION_SUBSTREAM_NAME, |
357 | 344 | maintain_connection_active_with_silent_audio: bool = False, |
358 | 345 | ): |
359 | 346 | """Initializes the SpeechToText processor. |
|
0 commit comments