|
5 | 5 | import sys
|
6 | 6 |
|
7 | 7 | 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 | +""" |
8 | 28 |
|
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.') |
11 | 31 | print('Type anything to start.')
|
12 | 32 |
|
| 33 | +lang = 'en' |
| 34 | +tld = 'com' |
| 35 | + |
13 | 36 | while (True):
|
14 | 37 | s = input('> ')
|
15 | 38 | if s.strip() == ':quit':
|
16 | 39 | break
|
17 | 40 | elif s.strip() == ':proxy':
|
18 |
| - server = input('HTTP Proxy server: ') |
| 41 | + server = input('HTTP proxy server: ') |
19 | 42 | os.environ['http_proxy'] = server
|
20 | 43 | os.environ['https_proxy'] = server
|
21 | 44 | print('Proxy is set.\n')
|
22 | 45 | 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 |
23 | 67 |
|
24 | 68 | print('Generating...', end='')
|
25 | 69 | sys.stdout.flush()
|
|
28 | 72 | except:
|
29 | 73 | pass
|
30 | 74 | try:
|
31 |
| - tts = gtts(s) |
| 75 | + tts = gtts(s, lang=lang, tld=tld) |
32 | 76 | tts.save(temp + 'speech.mp3')
|
33 | 77 | except AssertionError:
|
34 | 78 | print(' Nothing to generate.\n')
|
|
0 commit comments