|
8 | 8 | from urllib.parse import urlencode
|
9 | 9 | from vocode import getenv
|
10 | 10 |
|
11 |
| -from vocode.streaming.models.transcriber import AssemblyAITranscriberConfig |
| 11 | +from vocode.streaming.models.transcriber import AssemblyAITranscriberConfig, TimeEndpointingConfig, PunctuationEndpointingConfig |
12 | 12 | from vocode.streaming.models.websocket import AudioMessage
|
13 | 13 | from vocode.streaming.transcriber.base_transcriber import (
|
14 | 14 | BaseAsyncTranscriber,
|
@@ -54,12 +54,18 @@ def __init__(
|
54 | 54 | )
|
55 | 55 | self._ended = False
|
56 | 56 | self.logger = logger or logging.getLogger(__name__)
|
57 |
| - if self.transcriber_config.endpointing_config: |
58 |
| - raise Exception("Assembly AI endpointing config not supported yet") |
59 |
| - |
60 | 57 | self.buffer = bytearray()
|
61 | 58 | self.audio_cursor = 0
|
62 |
| - self.terminate_msg = str.encode(json.dumps({"terminate_session": True})) |
| 59 | + |
| 60 | + if isinstance(self.transcriber_config.endpointing_config, (TimeEndpointingConfig, PunctuationEndpointingConfig)): |
| 61 | + self.transcriber_config.end_utterance_silence_threshold_milliseconds = int(self.transcriber_config.endpointing_config.time_cutoff_seconds * 1000) |
| 62 | + self.terminate_msg = json.dumps({"terminate_session": True}) |
| 63 | + self.end_utterance_silence_threshold_msg = ( |
| 64 | + None if self.transcriber_config.end_utterance_silence_threshold_milliseconds is None |
| 65 | + else json.dumps( |
| 66 | + {"end_utterance_silence_threshold": self.transcriber_config.end_utterance_silence_threshold_milliseconds} |
| 67 | + ) |
| 68 | + ) |
63 | 69 |
|
64 | 70 | async def ready(self):
|
65 | 71 | return True
|
@@ -107,6 +113,9 @@ async def process(self):
|
107 | 113 | ) as ws:
|
108 | 114 | await asyncio.sleep(0.1)
|
109 | 115 |
|
| 116 | + if self.end_utterance_silence_threshold_msg: |
| 117 | + await ws.send(self.end_utterance_silence_threshold_msg) |
| 118 | + |
110 | 119 | async def sender(ws): # sends audio to websocket
|
111 | 120 | while not self._ended:
|
112 | 121 | try:
|
|
0 commit comments