Skip to content

Commit d76d5d0

Browse files
committed
Add multi-language support
1 parent ad40746 commit d76d5d0

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
11
# cli-tts
22

33
Command Line Text-To-Speech using Google TTS
4+
5+
This is an interactive command line text-to-speech tool. Just enter text and the voice will be played.
6+
7+
Multi-language is supported.
8+
9+
## Quick Start
10+
11+
### macOS
12+
13+
``` bash
14+
$ git clone https://github.com/ReekyStive/cli-tts.git
15+
$ cd cli-tts
16+
17+
$ brew install ffmpeg
18+
# be sure ffmpeg is in PATH
19+
$ pip install -r requirements.txt
20+
21+
$ python tts.py
22+
```
23+
24+
### Windows
25+
26+
There's a package that already included everything:
27+
[Win32 Release](https://github.com/) // TODO
28+
29+
## Screenshots
30+
31+
// TODO
32+
33+
## Supported Languages
34+
35+
| Local accent | Language code | Top-level domain |
36+
| ------------------------- | ------------- | ---------------- |
37+
| English (Australia) | `en` | `com.au` |
38+
| English (United Kingdom) | `en` | `co.uk` |
39+
| English (United States) | `en` | `com` |
40+
| English (Canada) | `en` | `ca` |
41+
| English (India) | `en` | `co.in` |
42+
| English (Ireland) | `en` | `ie` |
43+
| English (South Africa) | `en` | `co.za` |
44+
| French (Canada) | `fr` | `ca` |
45+
| French (France) | `fr` | `fr` |
46+
| Mandarin (China Mainland) | `zh-CN` | `<any>` |
47+
| Mandarin (Taiwan) | `zh-TW` | `<any>` |
48+
| Portuguese (Brazil) | `pt` | `com.br` |
49+
| Portuguese (Portugal) | `pt` | `pt` |
50+
| Spanish (Mexico) | `es` | `com.mx` |
51+
| Spanish (Spain) | `es` | `es` |
52+
| Spanish (United States) | `es` | `com` |
53+
54+
## Requirements
55+
56+
- Python 3.x
57+
- Pip packages
58+
- gTTS
59+
- simpleaudio
60+
- ffmpeg (in PATH)

tts.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,65 @@
55
import sys
66

77
temp = './temp/'
8+
langs_help = """
9+
| Local accent | Language code | Top-level domain |
10+
| ------------------------- | ------------- | ---------------- |
11+
| English (Australia) | en | com.au |
12+
| English (United Kingdom) | en | co.uk |
13+
| English (United States) | en | com |
14+
| English (Canada) | en | ca |
15+
| English (India) | en | co.in |
16+
| English (Ireland) | en | ie |
17+
| English (South Africa) | en | co.za |
18+
| French (Canada) | fr | ca |
19+
| French (France) | fr | fr |
20+
| Mandarin (China Mainland) | zh-CN | any |
21+
| Mandarin (Taiwan) | zh-TW | any |
22+
| Portuguese (Brazil) | pt | com.br |
23+
| Portuguese (Portugal) | pt | pt |
24+
| Spanish (Mexico) | es | com.mx |
25+
| Spanish (Spain) | es | es |
26+
| Spanish (United States) | es | com |
27+
"""
828

9-
print('Google TTS version 1.0 by ReekyStive')
10-
print('Type ":quit" to quit, type ":proxy" to set proxy.')
29+
print('Google TTS version 1.1 by ReekyStive')
30+
print('Type ":quit" to quit, type ":help" for help.')
1131
print('Type anything to start.')
1232

33+
lang = 'en'
34+
tld = 'com'
35+
1336
while (True):
1437
s = input('> ')
1538
if s.strip() == ':quit':
1639
break
1740
elif s.strip() == ':proxy':
18-
server = input('HTTP Proxy server: ')
41+
server = input('HTTP proxy server: ')
1942
os.environ['http_proxy'] = server
2043
os.environ['https_proxy'] = server
2144
print('Proxy is set.\n')
2245
continue
46+
elif s.strip() == ':help':
47+
print(':quit - quit')
48+
print(':help - show help')
49+
print(':proxy - set proxy')
50+
print(':lang - set language and local accent')
51+
print(':langs - show all languages and local accents')
52+
print()
53+
continue
54+
elif s.strip() == ':lang':
55+
lang = input('Language code(default: en): ')
56+
if lang.strip() == '':
57+
lang = 'en'
58+
tld = input('Top-level domain(default: com): ')
59+
if tld.strip() == '':
60+
tld = 'com'
61+
print('Language and local accent is set.')
62+
print()
63+
continue
64+
elif s.strip() == ':langs':
65+
print(langs_help)
66+
continue
2367

2468
print('Generating...', end='')
2569
sys.stdout.flush()
@@ -28,7 +72,7 @@
2872
except:
2973
pass
3074
try:
31-
tts = gtts(s)
75+
tts = gtts(s, lang=lang, tld=tld)
3276
tts.save(temp + 'speech.mp3')
3377
except AssertionError:
3478
print(' Nothing to generate.\n')

0 commit comments

Comments
 (0)