19
19
# We will collect the is_final=true messages here so we can use them when the person finishes speaking
20
20
is_finals = []
21
21
22
+
22
23
def main ():
23
24
try :
24
25
# example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM
@@ -32,7 +33,7 @@ def main():
32
33
dg_connection = deepgram .listen .live .v ("1" )
33
34
34
35
def on_open (self , open , ** kwargs ):
35
- print (f"Deepgram Connection Open" )
36
+ print (f"Connection Open" )
36
37
37
38
def on_message (self , result , ** kwargs ):
38
39
global is_finals
@@ -47,7 +48,7 @@ def on_message(self, result, **kwargs):
47
48
# Speech Final means we have detected sufficent silence to consider this end of speech
48
49
# Speech final is the lowest latency result as it triggers as soon an the endpointing value has triggered
49
50
if result .speech_final :
50
- utterance = ' ' .join (is_finals )
51
+ utterance = " " .join (is_finals )
51
52
print (f"Speech Final: { utterance } " )
52
53
is_finals = []
53
54
else :
@@ -58,26 +59,27 @@ def on_message(self, result, **kwargs):
58
59
print (f"Interim Results: { sentence } " )
59
60
60
61
def on_metadata (self , metadata , ** kwargs ):
61
- print (f"Deepgram Metadata: { metadata } " )
62
+ print (f"Metadata: { metadata } " )
62
63
63
64
def on_speech_started (self , speech_started , ** kwargs ):
64
- print (f"Deepgram Speech Started" )
65
+ print (f"Speech Started" )
65
66
66
67
def on_utterance_end (self , utterance_end , ** kwargs ):
68
+ print (f"Utterance End" )
67
69
global is_finals
68
70
if len (is_finals ) > 0 :
69
- utterance = ' ' .join (is_finals )
70
- print (f"Deepgram Utterance End: { utterance } " )
71
+ utterance = " " .join (is_finals )
72
+ print (f"Utterance End: { utterance } " )
71
73
is_finals = []
72
74
73
75
def on_close (self , close , ** kwargs ):
74
- print (f"Deepgram Connection Closed" )
76
+ print (f"Connection Closed" )
75
77
76
78
def on_error (self , error , ** kwargs ):
77
- print (f"Deepgram Handled Error: { error } " )
79
+ print (f"Handled Error: { error } " )
78
80
79
81
def on_unhandled (self , unhandled , ** kwargs ):
80
- print (f"Deepgram Unhandled Websocket Message: { unhandled } " )
82
+ print (f"Unhandled Websocket Message: { unhandled } " )
81
83
82
84
dg_connection .on (LiveTranscriptionEvents .Open , on_open )
83
85
dg_connection .on (LiveTranscriptionEvents .Transcript , on_message )
@@ -102,7 +104,7 @@ def on_unhandled(self, unhandled, **kwargs):
102
104
utterance_end_ms = "1000" ,
103
105
vad_events = True ,
104
106
# Time in milliseconds of silence to wait for before finalizing speech
105
- endpointing = 300
107
+ endpointing = 300 ,
106
108
)
107
109
108
110
addons = {
0 commit comments