From dabe5b0fe2f908ca114cb7fc12f732da7f7b5f68 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Thu, 22 Apr 2021 20:10:40 -0700 Subject: [PATCH] Switch TTS from mimic to flite --- README.md | 8 +++++--- go.mod | 1 + go.sum | 2 ++ plugins/shell/shell.go | 14 ++++++++++---- symbols.go | 18 ++++-------------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 861c573..e7d6dc7 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,15 @@ Personal voice assistant written in go using DeepSpeech. This was mainly created The prerequisites for trident are: - libdeepspeech and DeepSpeech models (speech to text) -- mimic (text to speech) +- flite (text to speech) - go `libdeepspeech` along with its models can be found in [its github releases](https://github.com/mozilla/DeepSpeech/releases/). Be sure to download the `native_client` tarball for your platform and the `.pbmm` and `.scorer` files. -`mimic` can be installed via an [install script](https://github.com/MycroftAI/mycroft-core/blob/dev/scripts/install-mimic.sh) or its AUR package if using Arch Linux or its derivatives. - +`flite` can be installed via your distribution's repositories: +- Debian/Ubuntu: `sudo apt install flite-dev` +- Fedora: `sudo dnf install flite-devel` +- Arch: `sudo pacman -S flite festival-us` ### Installation Move the previously downloaded models (`.pbmm` and `.scorer`) into this repo as `deepspeech.pbmm` and `deepspeech.scorer`. Then, follow the next steps. diff --git a/go.mod b/go.mod index c3b87de..cfe203d 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/asticode/go-astideepspeech v0.10.0 + github.com/gen2brain/flite-go v0.0.0-20170519100317-f4df2119132c github.com/gen2brain/malgo v0.10.29 github.com/pelletier/go-toml v1.9.0 github.com/rs/zerolog v1.21.0 diff --git a/go.sum b/go.sum index 39cf1ae..101c2d8 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/cryptix/wav v0.0.0-20180415113528-8bdace674401/go.mod h1:knK8fd+KPlGGqSUWogv1DQzGTwnfUvAi0cIoWyOG7+U= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gen2brain/flite-go v0.0.0-20170519100317-f4df2119132c h1:JBlwZJSYopoPXh0dLN9GGw750uhU08VjKKpl+uX5pE4= +github.com/gen2brain/flite-go v0.0.0-20170519100317-f4df2119132c/go.mod h1:Wv0H30ZpZPf4CrBNqgiG2S4G0CDtZWS2i87JnPtv9LI= github.com/gen2brain/malgo v0.10.29 h1:bTYiUTUKJsEomNby+W0hgyLrOttUXIk4lTEnKA54iqM= github.com/gen2brain/malgo v0.10.29/go.mod h1:zHSUNZAXfCeNsZou0RtQ6Zk7gDYLIcKOrUWtAdksnEs= github.com/pelletier/go-toml v1.9.0 h1:NOd0BRdOKpPf0SxkL3HxSQOG7rNh+4kl6PHcBPFs7Q0= diff --git a/plugins/shell/shell.go b/plugins/shell/shell.go index 44d994c..b969662 100644 --- a/plugins/shell/shell.go +++ b/plugins/shell/shell.go @@ -21,18 +21,21 @@ package shell import ( "os" "os/exec" + "trident" ) func RunPlugin(program string, data map[string]interface{}) { - var shell string - var ok bool // Attempt to get shell from config, asserting as string - shell, ok = data["shell"].(string) + shell, ok := data["shell"].(string) // If unsuccessful if !ok { // Set shell to default (/bin/sh) shell = "/bin/sh" } + sayOutput, ok := data["sayOutput"].(bool) + if !ok { + sayOutput = false + } // Create command using configured shell or default (/bin/sh) cmd := exec.Command(shell, "-c", program) // Set command environment to system environment @@ -40,5 +43,8 @@ func RunPlugin(program string, data map[string]interface{}) { // Set command's standard error to system standard error cmd.Stderr = os.Stderr // Run command, ignoring error - _ = cmd.Run() + output, _ := cmd.Output() + if sayOutput { + trident.Say(string(output)) + } } diff --git a/symbols.go b/symbols.go index ab2ccfb..3713875 100644 --- a/symbols.go +++ b/symbols.go @@ -18,8 +18,8 @@ package main import ( + "github.com/gen2brain/flite-go" "github.com/traefik/yaegi/interp" - "os/exec" "reflect" ) @@ -29,17 +29,7 @@ var tridentSymbols = interp.Exports{"trident": { }} // Function to say text using mimic text-to-speech -func Say(text string, args ...string) { - // If mimic exists in PATH - if _, err := exec.LookPath("mimic"); err == nil { - // Set initial argument slice to contain text - argSlice := []string{"-t", text} - // Add any additional arguments to slice - argSlice = append(argSlice, args...) - // Create and run command - exec.Command("mimic", argSlice...).Run() - } else { - // If mimic does not exist in PATH, warn user - log.Warn().Err(err).Str("text", text).Msg("Cannot perform text to speech") - } +func Say(text string) { + voice, _ := flite.VoiceSelect("slt") + flite.TextToSpeech(text, voice, "play") } \ No newline at end of file