Fix doc path
[opentx.git] / tools / release22 / tts.py
blob04781e2ccea4280d347f1f938e24f7f7877cc3ca
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 # This script is a modified version to support Linux TTS fiel genration using PicoTTS
7 # Sound pack maintainers (incomplete list) by language alphabetical order
8 # Czech : Martin Hotar
9 # French : Bertrand Songis & André Bernet
10 # English : Rob Thompson & Martin Hotar
11 # German : Romolo Manfredini (Some corrections by Peer)
12 # Italian : Romolo Manfredini
13 # Portuguese : Romolo Manfredini
14 # Spanish : Romolo Manfredini (With the help of Jose Moreno)
16 # from __future__ import print_function
18 import os
19 import sys
20 import subprocess
21 import zipfile
22 from gtts import gTTS
23 from tts_common import *
24 board = "taranis"
26 reload(sys)
27 sys.setdefaultencoding('utf8')
29 SOURCE_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
30 lib_path = os.path.abspath(os.path.join(SOURCE_DIRECTORY, '..', '..', 'radio', 'util'))
31 sys.path.append(lib_path)
33 def generate(str, filename):
34 if 0:
35 output = "output.wav"
36 command = 'pico2wave -l=%s -w=%s "%s"' % (voice, output, str)
37 os.system(command.encode('utf-8'))
38 command = "sox %s -r 32000 %s reverse silence 1 0.1 0.1%% reverse" % (output, filename)
39 os.system(command.encode('utf-8'))
40 else:
41 output = u"output.mp3"
42 tts = gTTS(text=str, lang=voice[:2])
43 tts.save(output)
44 command = "sox %s -r 32000 %s tempo 1.2 norm" % (output, filename)
45 os.system(command.encode('utf-8'))
46 command = "rm -f output.mp3"
47 os.system(command.encode('utf-8'))
49 ################################################################
51 if __name__ == "__main__":
52 if "en" in sys.argv:
53 from tts_en import systemSounds, sounds
55 directory = "en"
56 voice = "en-US"
58 elif "fr" in sys.argv:
59 from tts_fr import systemSounds, sounds
61 directory = "fr"
62 voice = "fr-FR"
64 elif "it" in sys.argv:
65 from tts_it import systemSounds, sounds
67 directory = "it"
68 voice = "it-IT"
70 elif "de" in sys.argv:
71 from tts_de import systemSounds, sounds
73 directory = "de"
74 voice = "de-DE"
76 elif "es" in sys.argv:
77 from tts_es import systemSounds, sounds
79 directory = "es"
80 voice = "es-ES"
82 elif "cz" in sys.argv:
83 from tts_cz import systemSounds, sounds
85 directory = "cz"
86 voice = "cs-CZ"
88 elif "ru" in sys.argv:
89 from tts_ru import systemSounds, sounds
91 directory = "ru"
92 voice = "ru-RU"
94 elif "pt" in sys.argv:
95 from tts_pt import systemSounds, sounds
97 directory = "pt"
98 voice = "pt-PT"
100 else:
101 print("which language?")
102 exit()
104 if "csv" in sys.argv:
105 path = "/tmp/SOUNDS/" + directory + "/SYSTEM/"
106 if not os.path.exists(path):
107 os.makedirs(path)
108 os.chdir(path)
109 with open("%s-%s.csv" % (voice, board), "wb") as csvFile:
110 for s, f in systemSounds:
111 if s and f:
112 l = u""
113 if board in ("sky9x", "taranis"):
114 l += u"SOUNDS/%s/SYSTEM;" % directory
115 l += f + u";" + s + u"\n"
116 csvFile.write(l.encode("utf-8"))
117 for s, f in sounds:
118 if s and f:
119 l = u""
120 if board in ("sky9x", "taranis"):
121 l += u"SOUNDS/%s;" % directory
122 l += f + u";" + s + u"\n"
123 csvFile.write(l.encode("utf-8"))
125 if "psv" in sys.argv:
126 path = "/tmp/SOUNDS/" + directory + "/"
127 if not os.path.exists(path):
128 os.makedirs(path)
129 os.chdir(path)
130 with open("%s-%s.psv" % (voice, board), "wb") as csvFile:
131 for s, f in systemSounds:
132 if s and f:
133 l = u"SYSTEM|" + f.replace(".wav", "") + u"|" + s + u"\r\n"
134 csvFile.write(l.encode("windows-1251"))
135 for s, f in sounds:
136 if s and f:
137 l = u"|" + f.replace(".wav", "") + u"|" + s + u"\r\n"
138 csvFile.write(l.encode("windows-1251"))
141 if "files" in sys.argv:
142 path = "/tmp/SOUNDS/" + directory + "/SYSTEM/"
143 if not os.path.exists(path):
144 os.makedirs(path)
145 os.chdir(path)
146 for s, f in systemSounds:
147 if s and f:
148 generate(s, f)
149 os.chdir("..")
150 for s, f in sounds:
151 if s and f:
152 generate(s, f)