Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Examples to Always Display UtteranceEnd Even If Not Using to Process Transcription #386

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions examples/streaming/async_microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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 = {
Expand Down
22 changes: 12 additions & 10 deletions examples/streaming/microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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 = {
Expand Down
Loading