Skip to content

Commit f87ab99

Browse files
committed
fix empty strings on failed transcription
1 parent f219ca1 commit f87ab99

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pkg/agent/loop.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,12 @@ func (al *AgentLoop) transcribeAudioInMessage(ctx context.Context, msg bus.Inbou
438438
transcriptions = append(transcriptions, result.Text)
439439
}
440440

441-
al.sendTranscriptionFeedback(msg.Channel, msg.ChatID, msg.MessageID, transcriptions)
442-
443441
if len(transcriptions) == 0 {
444442
return msg
445443
}
446444

445+
al.sendTranscriptionFeedback(msg.Channel, msg.ChatID, msg.MessageID, transcriptions)
446+
447447
// Replace audio annotations sequentially with transcriptions.
448448
idx := 0
449449
newContent := audioAnnotationRe.ReplaceAllStringFunc(msg.Content, func(match string) string {
@@ -475,9 +475,16 @@ func (al *AgentLoop) sendTranscriptionFeedback(channel, chatID string, messageID
475475
pubCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
476476
defer cancel()
477477

478+
var nonEmpty []string
479+
for _, t := range validTexts {
480+
if t != "" {
481+
nonEmpty = append(nonEmpty, t)
482+
}
483+
}
484+
478485
var feedbackMsg string
479-
if len(validTexts) > 0 {
480-
feedbackMsg = "Transcript: " + strings.Join(validTexts, "\n")
486+
if len(nonEmpty) > 0 {
487+
feedbackMsg = "Transcript: " + strings.Join(nonEmpty, "\n")
481488
} else {
482489
feedbackMsg = "No voice detected in the audio"
483490
}

0 commit comments

Comments
 (0)