@@ -35,6 +35,13 @@ export interface STTOptions {
3535 dictation : boolean ;
3636 diarize : boolean ;
3737 numerals : boolean ;
38+ /**
39+ * Enable eager end-of-turn detection for preemptive generation.
40+ * When set to a value between 0.3-0.9, Deepgram will emit EagerEndOfTurn events
41+ * when it detects a pause in speech, allowing the agent to start generating responses
42+ * preemptively.
43+ */
44+ eagerEotThreshold ?: number ;
3845}
3946
4047const defaultSTTOptions : STTOptions = {
@@ -161,6 +168,7 @@ export class SpeechStream extends stt.SpeechStream {
161168 keyterm : this . #opts. keyterm ,
162169 profanity_filter : this . #opts. profanityFilter ,
163170 language : this . #opts. language ,
171+ eager_eot_threshold : this . #opts. eagerEotThreshold ,
164172 } ;
165173 Object . entries ( params ) . forEach ( ( [ k , v ] ) => {
166174 if ( v !== undefined ) {
@@ -326,6 +334,29 @@ export class SpeechStream extends stt.SpeechStream {
326334
327335 break ;
328336 }
337+ case 'EagerEndOfTurn' : {
338+ // Deepgram has detected a pause in speech, but the user is technically
339+ // still speaking. Send a preflight event to enable preemptive generation.
340+ const metadata = json [ 'metadata' ] ;
341+ const requestId = metadata [ 'request_id' ] ;
342+ this . #requestId = requestId ;
343+
344+ const alternatives = liveTranscriptionToSpeechData ( this . #opts. language ! , json ) ;
345+
346+ if ( alternatives [ 0 ] && alternatives [ 0 ] . text ) {
347+ this . #logger. debug (
348+ { transcript : alternatives [ 0 ] . text , confidence : alternatives [ 0 ] . confidence } ,
349+ 'received eager end-of-turn event' ,
350+ ) ;
351+
352+ this . queue . put ( {
353+ type : stt . SpeechEventType . PREFLIGHT_TRANSCRIPT ,
354+ alternatives : [ alternatives [ 0 ] , ...alternatives . slice ( 1 ) ] ,
355+ } ) ;
356+ }
357+
358+ break ;
359+ }
329360 case 'Metadata' : {
330361 break ;
331362 }
0 commit comments