From aafa36ad611966e19b6b8f9795bb2e6123a30117 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Thu, 22 Apr 2021 20:13:47 -0700 Subject: [PATCH] Add SayWithVoice to yaegi symbols --- config.go | 2 +- main.go | 4 ++-- plugins.go | 1 - symbols.go | 18 ++++++++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index b2b9dea..815e8e1 100644 --- a/config.go +++ b/config.go @@ -93,4 +93,4 @@ func configEnv() (gopath, configDir, execDir, confPath string) { } // Return all variables return -} \ No newline at end of file +} diff --git a/main.go b/main.go index bd3f021..f21dd9d 100644 --- a/main.go +++ b/main.go @@ -208,7 +208,7 @@ func main() { // Create goroutine to clean stream every minute go func() { for { - time.Sleep(20*time.Second) + time.Sleep(20 * time.Second) // Lock mutex of stream safeStream.Lock() // Reset stream and buffer @@ -224,7 +224,7 @@ func main() { var tts string listenForActivation := true for { - time.Sleep(200*time.Millisecond) + time.Sleep(200 * time.Millisecond) // Convert captured raw audio to slice of int16 slice, err := convToInt16Slice(captured) if err != nil { diff --git a/plugins.go b/plugins.go index 06b29b5..766de64 100644 --- a/plugins.go +++ b/plugins.go @@ -100,4 +100,3 @@ func initPlugins(gopath string) map[string]pluginFunc { } return out } - diff --git a/symbols.go b/symbols.go index 3713875..6a311de 100644 --- a/symbols.go +++ b/symbols.go @@ -25,11 +25,21 @@ import ( // Create custom package for trident var tridentSymbols = interp.Exports{"trident": { - "Say": reflect.ValueOf(Say), + "Say": reflect.ValueOf(Say), + "SayWithVoice": reflect.ValueOf(SayWithVoice), }} // Function to say text using mimic text-to-speech func Say(text string) { - voice, _ := flite.VoiceSelect("slt") - flite.TextToSpeech(text, voice, "play") -} \ No newline at end of file + fliteVoice, _ := flite.VoiceSelect("slt") + flite.TextToSpeech(text, fliteVoice, "play") +} + +func SayWithVoice(text, voice string) error { + fliteVoice, err := flite.VoiceSelect(voice) + if err != nil { + return err + } + flite.TextToSpeech(text, fliteVoice, "play") + return nil +}