diff --git a/helpers.go b/helpers.go index e7c2159..d6efa4e 100644 --- a/helpers.go +++ b/helpers.go @@ -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 @@ -36,7 +37,7 @@ func ProcessSamples(model whisper.Model, samples []float32) (finalText string) { finalText += fmt.Sprintf(" %v", segment.Text) } - return finalText + return finalText, err } diff --git a/main.go b/main.go index 0776d30..85a78d3 100644 --- a/main.go +++ b/main.go @@ -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 } @@ -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