Skip to content

Commit

Permalink
Add error to ProcessSamples
Browse files Browse the repository at this point in the history
  • Loading branch information
chinese-soup committed Apr 19, 2023
1 parent f0439e0 commit 37c3e7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import (
"os"
)

func ProcessSamples(model whisper.Model, samples []float32) (finalText string) {
func ProcessSamples(model whisper.Model, samples []float32) (finalText string, err error) {
// TODO: Fix err handling

// Process samples
context, err := model.NewContext()
if err != nil {
panic(err)
return finalText, err
}

if err := context.SetLanguage("auto"); err != nil {
log.Printf("failed to set language to auto-detect")
return finalText, err
}

if err := context.Process(samples, nil); err != nil {
panic(err)
return finalText, err
}

// Print out the results
Expand All @@ -36,7 +37,7 @@ func ProcessSamples(model whisper.Model, samples []float32) (finalText string) {
finalText += fmt.Sprintf(" %v", segment.Text)
}

return finalText
return finalText, err

}

Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ func main() {

// Let's go through each update that we're getting from Telegram.
for update := range updates {
// Telegram can send many types of updates depending on what your Bot
// is up to. We only want to look at messages for now, so we can
// discard any other updates.
// Discard if not message.
if update.Message == nil {
continue
}

// Discard if not voice message.
if update.Message.Voice == nil {
continue
}
Expand Down Expand Up @@ -76,7 +75,12 @@ func main() {
log.Printf("Unfortunately this happened: %v", err)
continue
}
recognizedText := ProcessSamples(whisperModel, samples)

recognizedText, err := ProcessSamples(whisperModel, samples)
if err != nil {
log.Printf("Error while processing samples from wave file: %v", err)
continue
}

// Now that we know we've gotten a new message, we can construct a
// reply! We'll take the Chat ID and Text from the incoming message
Expand Down

0 comments on commit 37c3e7a

Please sign in to comment.