diff --git a/core/http/endpoints/openai/realtime.go b/core/http/endpoints/openai/realtime.go index 32b08b3fd..8b17a8238 100644 --- a/core/http/endpoints/openai/realtime.go +++ b/core/http/endpoints/openai/realtime.go @@ -12,6 +12,7 @@ import ( "math" "os" "strconv" + "strings" "sync" "time" @@ -1923,7 +1924,7 @@ func commitUtteranceWithTranscript(ctx context.Context, utt []byte, live *liveUt // Generate an LLM response only when there is a transcript to feed it. A // sound-detection-only session (no transcription) has no LLM stage, so it // stops here after emitting the sound-detection event. - if session.InputAudioTranscription != nil && !session.TranscriptionOnly { + if session.InputAudioTranscription != nil && !session.TranscriptionOnly && strings.TrimSpace(transcript) != "" { generateResponse(ctx, session, utt, transcript, speaker, conv, t) } } diff --git a/core/http/endpoints/openai/realtime_semantic_vad_test.go b/core/http/endpoints/openai/realtime_semantic_vad_test.go index c3f5d7ef8..c36e13563 100644 --- a/core/http/endpoints/openai/realtime_semantic_vad_test.go +++ b/core/http/endpoints/openai/realtime_semantic_vad_test.go @@ -355,6 +355,19 @@ var _ = Describe("commitUtteranceWithTranscript", func() { Expect(tr.countEvents(types.ServerEventTypeConversationItemInputAudioTranscriptionCompleted)).To(Equal(1)) }) + + It("does not generate a response for a blank transcript", func() { + session, model := itSession(nil) + model.transcribeFinal = &schema.TranscriptionResult{Text: " \t\n"} + tr := &fakeTransport{} + conv := &Conversation{} + + commitUtterance(context.Background(), []byte{1, 2}, session, conv, tr) + + Expect(tr.countEvents(types.ServerEventTypeConversationItemInputAudioTranscriptionCompleted)).To(Equal(1)) + Expect(conv.Items).To(BeEmpty()) + Expect(tr.countEvents(types.ServerEventTypeResponseCreated)).To(Equal(0)) + }) }) // transcribeUtterance is the retranscribe gate's offline decode of the