Fix done condition in playActivationSound and improve timing of loops

This commit is contained in:
Elara 2021-04-22 20:00:02 -07:00
parent c5956d3115
commit ffec012ca0
2 changed files with 12 additions and 3 deletions

View File

@ -84,11 +84,16 @@ func playActivationTone(ctx *malgo.AllocatedContext) error {
// Create new channel waiting for completion // Create new channel waiting for completion
done := make(chan bool) done := make(chan bool)
doneVar := false
onSamples := func(output, _ []byte, _ uint32) { onSamples := func(output, _ []byte, _ uint32) {
// Read as much audio into output as will fit // Read as much audio into output as will fit
n, err := io.ReadFull(wavReader, output) n, err := io.ReadFull(wavReader, output)
// If error occurred or no bytes read // 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 // Signal completion
done <- true done <- true
} }

View File

@ -45,6 +45,7 @@ func main() {
// Define and parse command line flags // Define and parse command line flags
tfLogLevel := flag.Int("tf-log-level", 2, "Log level for TensorFlow") tfLogLevel := flag.Int("tf-log-level", 2, "Log level for TensorFlow")
verbose = flag.BoolP("verbose", "v", false, "Log more events") 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") 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") 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") 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 // Create goroutine to clean stream every minute
go func() { go func() {
for { for {
time.Sleep(time.Minute) time.Sleep(20*time.Second)
// Lock mutex of stream // Lock mutex of stream
safeStream.Lock() safeStream.Lock()
// Reset stream and buffer // Reset stream and buffer
@ -223,7 +224,7 @@ func main() {
var tts string var tts string
listenForActivation := true listenForActivation := true
for { for {
time.Sleep(time.Second) time.Sleep(200*time.Millisecond)
// Convert captured raw audio to slice of int16 // Convert captured raw audio to slice of int16
slice, err := convToInt16Slice(captured) slice, err := convToInt16Slice(captured)
if err != nil { if err != nil {
@ -240,6 +241,9 @@ func main() {
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Error intermediate decoding stream") 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 decoded string contains activation phrase and listenForActivation is true
if strings.Contains(tts, config.ActivationPhrase) && listenForActivation { if strings.Contains(tts, config.ActivationPhrase) && listenForActivation {
// Play activation tone // Play activation tone