official site download link: download
need to add to path to do next steps.
we'll be able to run Python scripts without typing extra file location info now.
default settings on [Install Now] should be good.
use the search in the start menu.
search for [Command Prompt]
more info about gTTS:
gTTS documentation
we're entering 3 commands (enter 1 line at a time):
leave command prompt open after entering commands
cd %homepath%
what this does:
mkdir tts-folder && cd tts-folder
pip install gTTS
this folder should be at C:\Users\[your username]\tts-folder
right-click / then look for New / then Text Document
rename it to tts.py
hit yes.
right-click / then look for [Edit with IDLE] / then [Edit with IDLE]
what the code does (3 sections):
# SECTION ONE - COMMAND PROMPT OPTIONS
## add text, filename, language, and play options
## so you don't have to rewrite the script ----------------------------------------------
import argparse
parser = argparse.ArgumentParser(
description="generates TTS files with Google Translate voices."
)
parser.add_argument("-t","--text", help="text in quotes you want to read: \"like this\"")
parser.add_argument("-f","--filename", help="tts output filename (no spaces): like-this")
parser.add_argument("-l","--lang", help="language code, type [ gtts-cli --all ] to see all codes")
parser.add_argument("--play", action="store_true", help="play TTS in your default MP3 player")
args = parser.parse_args()
text = "Jega Senesys"
if args.text:
text = args.text
code = "en"
if args.lang:
code = args.lang
filename = "output"
if args.filename:
filename = args.filename
# SECTION TWO - RUN GOOGLE TTS / MAKE TTS FILE
## code we added with 'pip install gTTS' ------------------------------------------------
from gtts import gTTS
tts = gTTS(args.text, lang=code)
tts.save(filename+'.mp3')
# SECTION THREE - OPEN TTS MP3 FILE IN DEFAULT PLAYER
## will use system default program
## plays mp3s in Groove on Windows 10, i think ------------------------------------------
import os
if args.play:
os.system("start " + filename + ".mp3")
save the file and go back to Command Prompt
we're running the script in the tts-folder
bold lines can be typed into Command Prompt in the tts-folder
- python tts.py --play
- uses defaults for text("Jega Senesys"), language("en"), filename("output.mp3"), plays file.
- python tts.py --text "today was a good day" --play
- replace default text, use default language + filename, plays file
- python tts.py --text "konnichiwatson" --lang ja --play
- replace default text + language("ja"-Japanese), use default filename, plays file
- python tts.py --text "konnichiwatson" --lang ja --filename kwatson --play
- replace default text + language + filename(kwatson.mp3), plays file
- python tts.py -t "konnichiwatson" -l ja -f konwatson --play
- similar to above but shorter, filename(konwatson.mp3), plays file
- python tts.py -t "konbanwatson" -l ja -f konbanwatson
- filename(konbanwatson.mp3), DOESN'T play file
- python tts.py --help
- script help
- gtts-cli --all
- lists other language codes you may wanna try.
hopefully this was the type of thing you were looking for. o7