fix empty strings on failed transcription
This commit is contained in:
parent
f219ca1263
commit
f87ab99833
1 changed files with 11 additions and 4 deletions
|
|
@ -438,12 +438,12 @@ func (al *AgentLoop) transcribeAudioInMessage(ctx context.Context, msg bus.Inbou
|
||||||
transcriptions = append(transcriptions, result.Text)
|
transcriptions = append(transcriptions, result.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
al.sendTranscriptionFeedback(msg.Channel, msg.ChatID, msg.MessageID, transcriptions)
|
|
||||||
|
|
||||||
if len(transcriptions) == 0 {
|
if len(transcriptions) == 0 {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
al.sendTranscriptionFeedback(msg.Channel, msg.ChatID, msg.MessageID, transcriptions)
|
||||||
|
|
||||||
// Replace audio annotations sequentially with transcriptions.
|
// Replace audio annotations sequentially with transcriptions.
|
||||||
idx := 0
|
idx := 0
|
||||||
newContent := audioAnnotationRe.ReplaceAllStringFunc(msg.Content, func(match string) string {
|
newContent := audioAnnotationRe.ReplaceAllStringFunc(msg.Content, func(match string) string {
|
||||||
|
|
@ -475,9 +475,16 @@ func (al *AgentLoop) sendTranscriptionFeedback(channel, chatID string, messageID
|
||||||
pubCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
pubCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
var nonEmpty []string
|
||||||
|
for _, t := range validTexts {
|
||||||
|
if t != "" {
|
||||||
|
nonEmpty = append(nonEmpty, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var feedbackMsg string
|
var feedbackMsg string
|
||||||
if len(validTexts) > 0 {
|
if len(nonEmpty) > 0 {
|
||||||
feedbackMsg = "Transcript: " + strings.Join(validTexts, "\n")
|
feedbackMsg = "Transcript: " + strings.Join(nonEmpty, "\n")
|
||||||
} else {
|
} else {
|
||||||
feedbackMsg = "No voice detected in the audio"
|
feedbackMsg = "No voice detected in the audio"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue