Skip to content

Commit

Permalink
Update stt.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Oct 29, 2024
1 parent 22e4fa5 commit dd1e590
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def _sanitize_options(self, *, language: str | None = None) -> STTOptions:
class SpeechStream(stt.SpeechStream):
_KEEPALIVE_MSG: str = json.dumps({"type": "KeepAlive"})
_CLOSE_MSG: str = json.dumps({"type": "CloseStream"})
_FINALIZE_MSG: str = json.dumps({"type": "Finalize"})

def __init__(
self,
Expand All @@ -271,7 +272,7 @@ def __init__(
self._audio_energy_filter = _AudioEnergyFilter()

self._pushed_audio_duration = 0.0
self._request_id = 0
self._request_id = ""

@utils.log_exceptions(logger=logger)
async def _main_task(self) -> None:
Expand Down Expand Up @@ -385,6 +386,7 @@ async def send_task():
)
self._pushed_audio_duration = 0.0
self._event_ch.send_nowait(usage_event)
await ws.send_str(SpeechStream._FINALIZE_MSG)

# tell deepgram we are done sending audio/inputs
closing_ws = True
Expand Down Expand Up @@ -444,6 +446,7 @@ def _process_stream_event(self, data: dict) -> None:
# https://developers.deepgram.com/docs/understand-endpointing-interim-results#using-endpointing-speech_final
# for more information about the different types of events
elif data["type"] == "Results":
print(data)
metadata = data["metadata"]
request_id = metadata["request_id"]
is_final_transcript = data["is_final"]
Expand Down

0 comments on commit dd1e590

Please sign in to comment.