Skip to content

feat(realtime): Add speech started and stopped events #5856

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

Merged
merged 1 commit into from
Jul 18, 2025
Merged
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
21 changes: 20 additions & 1 deletion core/http/endpoints/openai/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio
}()

silenceThreshold := float64(session.TurnDetection.SilenceDurationMs) / 1000
speechStarted := false
startTime := time.Now()

ticker := time.NewTicker(300 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -691,7 +693,16 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio
continue
}

// TODO: Send input_audio_buffer.speech_started and input_audio_buffer.speech_stopped
if !speechStarted {
sendEvent(c, types.InputAudioBufferSpeechStartedEvent{
ServerEventBase: types.ServerEventBase{
EventID: "event_TODO",
Type: types.ServerEventTypeInputAudioBufferSpeechStarted,
},
AudioStartMs: time.Now().Sub(startTime).Milliseconds(),
})
speechStarted = true
}

// Segment still in progress when audio ended
segEndTime := segments[len(segments)-1].GetEnd()
Expand All @@ -717,6 +728,14 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio
abytes := sound.Int16toBytesLE(aints)
// TODO: Remove prefix silence that is is over TurnDetectionParams.PrefixPaddingMs
go commitUtterance(vadContext, abytes, cfg, evaluator, session, conv, c)

sendEvent(c, types.InputAudioBufferSpeechStoppedEvent{
ServerEventBase: types.ServerEventBase{
EventID: "event_TODO",
Type: types.ServerEventTypeInputAudioBufferSpeechStopped,
},
AudioEndMs: time.Now().Sub(startTime).Milliseconds(),
})
}
}
}
Expand Down
Loading