From 3a29e0054c1092addb1a8dcbfdd71b5b367f856c Mon Sep 17 00:00:00 2001 From: David vonThenen <12752197+dvonthenen@users.noreply.github.com> Date: Wed, 8 May 2024 07:13:34 -0700 Subject: [PATCH] Update Examples to Always Display UtteranceEnd Even If Not Using to Process Transcription --- examples/streaming/async_microphone/main.py | 22 +++++++++++---------- examples/streaming/microphone/main.py | 22 +++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/examples/streaming/async_microphone/main.py b/examples/streaming/async_microphone/main.py index 3d2b668d..0e79fd67 100644 --- a/examples/streaming/async_microphone/main.py +++ b/examples/streaming/async_microphone/main.py @@ -21,6 +21,7 @@ # We will collect the is_final=true messages here so we can use them when the person finishes speaking is_finals = [] + async def main(): try: loop = asyncio.get_event_loop() @@ -44,7 +45,7 @@ async def main(): dg_connection = deepgram.listen.asynclive.v("1") async def on_open(self, open, **kwargs): - print(f"Deepgram Connection Open") + print(f"Connection Open") async def on_message(self, result, **kwargs): global is_finals @@ -59,7 +60,7 @@ async def on_message(self, result, **kwargs): # Speech Final means we have detected sufficent silence to consider this end of speech # Speech final is the lowest latency result as it triggers as soon an the endpointing value has triggered if result.speech_final: - utterance = ' '.join(is_finals) + utterance = " ".join(is_finals) print(f"Speech Final: {utterance}") is_finals = [] else: @@ -70,26 +71,27 @@ async def on_message(self, result, **kwargs): print(f"Interim Results: {sentence}") async def on_metadata(self, metadata, **kwargs): - print(f"Deepgram Metadata: {metadata}") + print(f"Metadata: {metadata}") async def on_speech_started(self, speech_started, **kwargs): - print(f"Deepgram Speech Started") + print(f"Speech Started") async def on_utterance_end(self, utterance_end, **kwargs): + print(f"Utterance End") global is_finals if len(is_finals) > 0: - utterance = ' '.join(is_finals) - print(f"Deepgram Utterance End: {utterance}") + utterance = " ".join(is_finals) + print(f"Utterance End: {utterance}") is_finals = [] async def on_close(self, close, **kwargs): - print(f"Deepgram Connection Closed") + print(f"Connection Closed") async def on_error(self, error, **kwargs): - print(f"Deepgram Handled Error: {error}") + print(f"Handled Error: {error}") async def on_unhandled(self, unhandled, **kwargs): - print(f"Deepgram Unhandled Websocket Message: {unhandled}") + print(f"Unhandled Websocket Message: {unhandled}") dg_connection.on(LiveTranscriptionEvents.Open, on_open) dg_connection.on(LiveTranscriptionEvents.Transcript, on_message) @@ -115,7 +117,7 @@ async def on_unhandled(self, unhandled, **kwargs): utterance_end_ms="1000", vad_events=True, # Time in milliseconds of silence to wait for before finalizing speech - endpointing=300 + endpointing=300, ) addons = { diff --git a/examples/streaming/microphone/main.py b/examples/streaming/microphone/main.py index 9905b60c..8d50c083 100644 --- a/examples/streaming/microphone/main.py +++ b/examples/streaming/microphone/main.py @@ -19,6 +19,7 @@ # We will collect the is_final=true messages here so we can use them when the person finishes speaking is_finals = [] + def main(): try: # example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM @@ -32,7 +33,7 @@ def main(): dg_connection = deepgram.listen.live.v("1") def on_open(self, open, **kwargs): - print(f"Deepgram Connection Open") + print(f"Connection Open") def on_message(self, result, **kwargs): global is_finals @@ -47,7 +48,7 @@ def on_message(self, result, **kwargs): # Speech Final means we have detected sufficent silence to consider this end of speech # Speech final is the lowest latency result as it triggers as soon an the endpointing value has triggered if result.speech_final: - utterance = ' '.join(is_finals) + utterance = " ".join(is_finals) print(f"Speech Final: {utterance}") is_finals = [] else: @@ -58,26 +59,27 @@ def on_message(self, result, **kwargs): print(f"Interim Results: {sentence}") def on_metadata(self, metadata, **kwargs): - print(f"Deepgram Metadata: {metadata}") + print(f"Metadata: {metadata}") def on_speech_started(self, speech_started, **kwargs): - print(f"Deepgram Speech Started") + print(f"Speech Started") def on_utterance_end(self, utterance_end, **kwargs): + print(f"Utterance End") global is_finals if len(is_finals) > 0: - utterance = ' '.join(is_finals) - print(f"Deepgram Utterance End: {utterance}") + utterance = " ".join(is_finals) + print(f"Utterance End: {utterance}") is_finals = [] def on_close(self, close, **kwargs): - print(f"Deepgram Connection Closed") + print(f"Connection Closed") def on_error(self, error, **kwargs): - print(f"Deepgram Handled Error: {error}") + print(f"Handled Error: {error}") def on_unhandled(self, unhandled, **kwargs): - print(f"Deepgram Unhandled Websocket Message: {unhandled}") + print(f"Unhandled Websocket Message: {unhandled}") dg_connection.on(LiveTranscriptionEvents.Open, on_open) dg_connection.on(LiveTranscriptionEvents.Transcript, on_message) @@ -102,7 +104,7 @@ def on_unhandled(self, unhandled, **kwargs): utterance_end_ms="1000", vad_events=True, # Time in milliseconds of silence to wait for before finalizing speech - endpointing=300 + endpointing=300, ) addons = {