This CLI is just a wrapper on Google Translate that can play TTS audio files in all languages that are supported on the web.
Some languages are available for translation but not for TTS, so those would fail. Don't now which ones, I didn't go through the whole list.
Although it didn't fail while it was under development, it may fail randomly if you abuse it.
This program should be cross-platform. Uses hajimehoshi/oto to play sounds, so it has the same requirements:
- macOS:
AudioToolbox.framework
required (automatically linked). - Linux: libasound2-dev required. (
apt install libasound2-dev
) - FreeBSD: OpenAL required. (
pkg install openal-soft
) - OpenBSD: OpenAL required. (
pkg_add -r openal
)
I've only tested on Linux. Open an issue if you found any.
IMPORTANT NOTE: _Binaries are compiled manually for linux. I cannot make goreleaser
work with CGO_ENABLED.
Feel free to change the path from /usr/local/bin
, just make sure go-tts
is available on your $PATH
(check with go-tts -h
).
$ curl -sfL https://raw.githubusercontent.com/guumaster/go-tts/master/install.sh | bash -s -- -b /usr/local/bin
Depending on the path you choose, it may need sudo
$ curl -sfL https://raw.githubusercontent.com/guumaster/go-tts/master/install.sh | sudo bash -s -- -b /usr/local/bin
Go to the Release page and pick one.
go get -u github.com/guumaster/go-tts
package main
import (
"fmt"
"github.com/guumaster/go-tts/pkg/tts"
)
func main() {
t := tts.NewGoogleTTS()
opts := *SayOptions{}
defer t.Close()
err := t.Say("it" "questo programma è fantastico", opts)
if err != nil {
panic(err)
}
// Other languages and options examples:
t.MustSay("zh-CN", "我喜欢它", &tts.SayOptions{Slow: true})
t.MustSay("my", "ကိုယ်ကြိုက်တယ်", opts)
t.MustSay("bn", "আমি এটা ভালোবাসি", opts)
t.MustSay("de", "ich liebe es", opts)
t.MustSay("ar", "احب هذا", opts)
t.MustSay("en", "I love it", opts)
t.MustSay("ja", "大好きです", opts)
t.MustSay("tr", "onu seviyorum", opts)
t.MustSay("es", "Me encanta", &tts.SayOptions{Slow: true})
t.MustSay("it", "Lo adoro", opts)
// Save a specific translation
err := tts.Save("en", "A locally saved file", "/tmp/myfile.mp3", opts)
if err != nil {
panic(err)
}
}
// Output:
// will play audios for every string you pass to Say() or MustSay() and a
// file called /tmp/myfile.mp3 will be created.
You can pass arguments:
$> go-tts --slow --lang "it" "questo programma è fantastico"
// Output:
// will play an audio for "this program is amazing" in italian
Or echo from other commands:
$> echo "che! esto es buenísimo pibe\!" | go-tts --lang "es-AR"
// Output:
// will play an audio for "hey! this is great dude!" in argentinian
USAGE:
go-tts <TEXT_TO_SAY>
echo "TEXT_TO_SAY" | go-tts
VERSION:
dev
AUTHOR:
guumaster <[email protected]>
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--slow, -s play audio slower (default: false)
--no-cache don't use file cache (default: false)
--help, -h show help (default: false)
--version, -v print the version (default: false)
The language parameter must be a ISO-639
compilant string. Ex: "es", "en", "kn", "zh-CN", etc.
If you use an unknown language, it will fail:
$> go-tts --lang "klingon" "hello unknown world?"
// Output:
language: tag is not well-formed
- Uses gosimple/slug to calc cache key
- Uses hajimehoshi/oto to play audio files
- Uses tosone/minimp3 to decode MP3 files
- Uses urfave/cli/v2 to run as CLI
This is loosely based on hegedustibor/htgo-tts, but without depending on mplayer, and with a better cache implementation.