1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-16 12:55:12 +03:00
opentx/tools/rc23/tts.py
2019-09-11 10:32:48 +02:00

152 lines
4.4 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This script is a modified version to support Linux TTS fiel genration using PicoTTS
# Sound pack maintainers (incomplete list) by language alphabetical order
# Czech : Martin Hotar
# French : Bertrand Songis & André Bernet
# English : Rob Thompson & Martin Hotar
# German : Romolo Manfredini (Some corrections by Peer)
# Italian : Romolo Manfredini
# Portuguese : Romolo Manfredini
# Spanish : Romolo Manfredini (With the help of Jose Moreno)
# from __future__ import print_function
import os
import sys
import subprocess
import zipfile
from gtts import gTTS
from tts_common import *
board = "taranis"
reload(sys)
sys.setdefaultencoding('utf8')
SOURCE_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.abspath(os.path.join(SOURCE_DIRECTORY, '..', '..', 'radio', 'util'))
sys.path.append(lib_path)
def generate(str, filename):
if 0:
output = "output.wav"
command = 'pico2wave -l=%s -w=%s "%s"' % (voice, output, str)
os.system(command.encode('utf-8'))
command = "sox %s -r 32000 %s reverse silence 1 0.1 0.1%% reverse" % (output, filename)
os.system(command.encode('utf-8'))
else:
output = u"output.mp3"
tts = gTTS(text=str, lang=voice[:2])
tts.save(output)
command = "sox --norm %s -r 32000 %s tempo 1.2" % (output, filename)
os.system(command.encode('utf-8'))
command = "rm -f output.mp3"
os.system(command.encode('utf-8'))
################################################################
if __name__ == "__main__":
if "en" in sys.argv:
from tts_en import systemSounds, sounds
directory = "en"
voice = "en-US"
elif "fr" in sys.argv:
from tts_fr import systemSounds, sounds
directory = "fr"
voice = "fr-FR"
elif "it" in sys.argv:
from tts_it import systemSounds, sounds
directory = "it"
voice = "it-IT"
elif "de" in sys.argv:
from tts_de import systemSounds, sounds
directory = "de"
voice = "de-DE"
elif "es" in sys.argv:
from tts_es import systemSounds, sounds
directory = "es"
voice = "es-ES"
elif "cz" in sys.argv:
from tts_cz import systemSounds, sounds
directory = "cz"
voice = "cs-CZ"
elif "ru" in sys.argv:
from tts_ru import systemSounds, sounds
directory = "ru"
voice = "ru-RU"
elif "pt" in sys.argv:
from tts_pt import systemSounds, sounds
directory = "pt"
voice = "pt-PT"
else:
print("which language?")
exit()
if "csv" in sys.argv:
path = "/tmp/SOUNDS/" + directory + "/SYSTEM/"
if not os.path.exists(path):
os.makedirs(path)
os.chdir(path)
with open("%s-%s.csv" % (voice, board), "wb") as csvFile:
for s, f in systemSounds:
if s and f:
l = u""
if board in ("sky9x", "taranis"):
l += u"SOUNDS/%s/SYSTEM;" % directory
l += f + u";" + s + u"\n"
csvFile.write(l.encode("utf-8"))
for s, f in sounds:
if s and f:
l = u""
if board in ("sky9x", "taranis"):
l += u"SOUNDS/%s;" % directory
l += f + u";" + s + u"\n"
csvFile.write(l.encode("utf-8"))
if "psv" in sys.argv:
path = "/tmp/SOUNDS/" + directory + "/"
if not os.path.exists(path):
os.makedirs(path)
os.chdir(path)
with open("%s-%s.psv" % (voice, board), "wb") as csvFile:
for s, f in systemSounds:
if s and f:
l = u"SYSTEM|" + f.replace(".wav", "") + u"|" + s + u"\r\n"
csvFile.write(l.encode("windows-1251"))
for s, f in sounds:
if s and f:
l = u"|" + f.replace(".wav", "") + u"|" + s + u"\r\n"
csvFile.write(l.encode("windows-1251"))
if "files" in sys.argv:
path = "/tmp/SOUNDS/" + directory + "/SYSTEM/"
if not os.path.exists(path):
os.makedirs(path)
os.chdir(path)
for s, f in systemSounds:
if s and f:
generate(s, f)
os.chdir("..")
for s, f in sounds:
if s and f:
generate(s, f)