diff --git a/Dockerfile b/Dockerfile index d7b47b6..645c5ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ LABEL maintainer="pedroetb@gmail.com" ARG APT_REPOSITORY="deb http://ftp.de.debian.org/debian stretch main non-free" ARG GOOGLE_SPEECH_VERSION=1.1.0 +ARG GTTS_VERSION=2.0.3 ARG ESPEAK_VERSION=1.48.04+dfsg-5+b1 ARG FESTIVAL_VERSION=1:2.4~release-3+b1 @@ -31,7 +32,8 @@ RUN echo ${APT_REPOSITORY} >> /etc/apt/sources.list && \ festvox-ellpc11k=${FESTVOX_ELLPC11K_VERSION} \ espeak=${ESPEAK_VERSION} && \ pip3 install \ - google_speech==${GOOGLE_SPEECH_VERSION} && \ + google_speech==${GOOGLE_SPEECH_VERSION} \ + gTTS==${GTTS_VERSION} && \ apt-get remove --purge -y \ python3-pip \ python3-setuptools \ diff --git a/README.md b/README.md index fedce04..63111d5 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,13 @@ First, you should install the supported TTS engines: ``` $ apt install python3 sox libsox-fmt-mp3 $ pip install google_speech +``` + +### gTTS -# Run only when you need to upgrade -$ pip install --upgrade pip -$ pip install google_speech --upgrade +``` +$ apt install python3 sox libsox-fmt-mp3 +$ pip install gTTS ``` ### Festival @@ -103,6 +106,14 @@ You need to be online to communicate with Google servers. Learn more at https://github.com/desbma/GoogleSpeech +### gTTS + +Google Text-to-Speech (gTTS) is a Python library and CLI tool to interface with Google Translate's text-to-speech API. + +You need to be online to communicate with Google servers. + +Learn more at https://github.com/pndurette/gTTS + ### Festival Festival is a free software multi-lingual speech synthesis workbench that runs on multiple-platforms offering black box text to speech, as well as an open architecture for research in speech synthesis. diff --git a/app.js b/app.js index 51aced0..eec8951 100644 --- a/app.js +++ b/app.js @@ -53,6 +53,8 @@ function getCmdWithArgs(fields) { if (voice === 'google_speech') { return getGoogleSpeechCmdWithArgs(fields); + } else if (voice === 'gtts') { + return getGttsCmdWithArgs(fields); } else if (voice === 'festival') { return getFestivalCmdWithArgs(fields); } else if (voice === 'espeak') { @@ -68,10 +70,21 @@ function getGoogleSpeechCmdWithArgs(fields) { language = fields.language, speed = fields.speed, - cmd = 'google_speech', - args = '-l ' + language + ' \"' + text + '\"' + ' -e overdrive 10 speed ' + speed; + cmd = 'google_speech' + ' -l ' + language + ' \"' + text + '\"' + ' -e overdrive 10 speed ' + speed; - return cmd + ' ' + args; + return cmd; +} + +function getGttsCmdWithArgs(fields) { + + var text = fields.textToSpeech, + language = fields.language, + speed = fields.speed, + speedParam = speed ? ' -s' : '', + + cmd = 'gtts-cli' + ' -l ' + language + speedParam + ' --nocheck \"' + text + '\"' + ' | play -t mp3 -'; + + return cmd; } function getFestivalCmdWithArgs(fields) { @@ -79,10 +92,9 @@ function getFestivalCmdWithArgs(fields) { var text = fields.textToSpeech, language = fields.language, - cmd = 'echo "' + text + '" | festival', - args = '--tts --heap 1000000 --language ' + language; + cmd = 'echo "' + text + '" | festival' + ' --tts --heap 1000000 --language ' + language; - return cmd + ' ' + args; + return cmd; } function getEspeakCmdWithArgs(fields) { @@ -93,10 +105,9 @@ function getEspeakCmdWithArgs(fields) { speed = Math.floor(fields.speed * 150), pitch = '70', - cmd = 'espeak', - args = '-v' + language + voiceCode + ' -s ' + speed + ' -p ' + pitch + ' \"' + text + '\"'; + cmd = 'espeak' + ' -v' + language + voiceCode + ' -s ' + speed + ' -p ' + pitch + ' \"' + text + '\"'; - return cmd + ' ' + args; + return cmd; } function onSpeechDone(args, err, stdout, stderr) { diff --git a/views/form.pug b/views/form.pug index cbe4072..764369b 100644 --- a/views/form.pug +++ b/views/form.pug @@ -31,6 +31,14 @@ html checked ) span GoogleSpeech + div.form-check-inline + label.form-check-label + input.form-check-input( + type='radio' + name='voice' + value='gtts' + ) + span gTTS div.form-check-inline label.form-check-label input.form-check-input(