diff --git a/audio.go b/audio.go index 2ef3ebd..78d50e0 100644 --- a/audio.go +++ b/audio.go @@ -84,11 +84,16 @@ func playActivationTone(ctx *malgo.AllocatedContext) error { // Create new channel waiting for completion done := make(chan bool) + doneVar := false onSamples := func(output, _ []byte, _ uint32) { // Read as much audio into output as will fit n, err := io.ReadFull(wavReader, output) // If error occurred or no bytes read - if err != nil || n == 0 { + if !doneVar && (err != nil || n == 0) { + if *verbose { + log.Debug().Msg("Sample output complete") + } + doneVar = true // Signal completion done <- true } diff --git a/main.go b/main.go index 2c40977..bd3f021 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ func main() { // Define and parse command line flags tfLogLevel := flag.Int("tf-log-level", 2, "Log level for TensorFlow") verbose = flag.BoolP("verbose", "v", false, "Log more events") + showDecode := flag.BoolP("show-decode", "d", false, "Show text to speech decodes") configPath := flag.StringP("config", "c", confPath, "Location of trident TOML config") modelPath := flag.StringP("model", "m", filepath.Join(execDir, "deepspeech.pbmm"), "Path to DeepSpeech model") scorerPath := flag.StringP("scorer", "s", filepath.Join(execDir, "deepspeech.scorer"), "Path to DeepSpeech scorer") @@ -207,7 +208,7 @@ func main() { // Create goroutine to clean stream every minute go func() { for { - time.Sleep(time.Minute) + time.Sleep(20*time.Second) // Lock mutex of stream safeStream.Lock() // Reset stream and buffer @@ -223,7 +224,7 @@ func main() { var tts string listenForActivation := true for { - time.Sleep(time.Second) + time.Sleep(200*time.Millisecond) // Convert captured raw audio to slice of int16 slice, err := convToInt16Slice(captured) if err != nil { @@ -240,6 +241,9 @@ func main() { if err != nil { log.Fatal().Err(err).Msg("Error intermediate decoding stream") } + if *showDecode { + log.Debug().Msg("TTS Decode: " + tts) + } // If decoded string contains activation phrase and listenForActivation is true if strings.Contains(tts, config.ActivationPhrase) && listenForActivation { // Play activation tone