mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 01:05:10 +03:00
TTS script
This commit is contained in:
parent
0ac6582225
commit
b9a74b0f89
1 changed files with 97 additions and 12 deletions
109
util/tts.py
109
util/tts.py
|
@ -1,24 +1,109 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os, sys, shutil, platform, subprocess
|
||||
import os, sys, shutil, platform, subprocess, wave, zipfile
|
||||
|
||||
def generate(str, idx):
|
||||
if platform.system() == "Windows":
|
||||
subprocess.Popen(["C:\Program Files\eSpeak\command_line\espeak.exe", "-w", "%04d.wav" % idx, str], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
if 'ad4' in sys.argv:
|
||||
subprocess.Popen(["D:\Perso\workspace\companion9x\AD4CONVERTER.EXE", "-E4", "%04d.WAV" % idx], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
result = None
|
||||
if str and platform.system() == "Windows":
|
||||
if "sapi" in sys.argv:
|
||||
if "speak" in sys.argv:
|
||||
tts.Speak(str)
|
||||
else:
|
||||
if isinstance(idx, int):
|
||||
result = "%04d.wav" % idx
|
||||
else:
|
||||
result = idx + ".wav"
|
||||
print result, str
|
||||
tts.SpeakToWave(result, str)
|
||||
else:
|
||||
subprocess.Popen(["C:\Program Files\eSpeak\command_line\espeak.exe", "-z", "-w", "%04d.wav" % idx, str], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
if not "speak" in sys.argv:
|
||||
if 'ad4' in sys.argv:
|
||||
subprocess.Popen(["D:\Perso\workspace\companion9x\AD4CONVERTER.EXE", "-E4", result], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
result = result.replace(".wav", ".ad4")
|
||||
else:
|
||||
try:
|
||||
os.remove("_"+result)
|
||||
except:
|
||||
pass
|
||||
os.rename(result, "_"+result)
|
||||
subprocess.Popen(["C:/Programs/ffmpeg/bin/ffmpeg.exe", "-y", "-i", "_"+result, "-acodec", "pcm_alaw", result], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
os.remove("_"+result)
|
||||
|
||||
if result:
|
||||
return [result]
|
||||
else:
|
||||
return []
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
sounds = []
|
||||
systemSounds = []
|
||||
|
||||
if "sapi" in sys.argv:
|
||||
import pyTTS
|
||||
tts = pyTTS.Create()
|
||||
tts.SetOutputFormat(16, 16, 1)
|
||||
# tts.Volume = 40
|
||||
tts.SetRate(1)
|
||||
if "list" in sys.argv:
|
||||
print tts.GetVoiceNames()
|
||||
|
||||
if "en" in sys.argv:
|
||||
if "sapi" in sys.argv:
|
||||
tts.SetVoiceByName("ScanSoftFiona_Full_22kHz")
|
||||
voice = "english-scottish"
|
||||
for i in range(20):
|
||||
generate(str(i), i)
|
||||
systemSounds.extend(generate(str(i), i))
|
||||
for i in range(20, 100, 10):
|
||||
generate(str(i), 20+(i-20)/10)
|
||||
generate("hundred", 28)
|
||||
generate("thousand", 29)
|
||||
systemSounds.extend(generate(str(i), 20+(i-20)/10))
|
||||
systemSounds.extend(generate("hundred", 28))
|
||||
systemSounds.extend(generate("thousand", 29))
|
||||
for i, s in enumerate(["hour", "hours", "minute", "minutes", "second", "seconds", "", "and", "minus"]):
|
||||
generate(s, 40+i)
|
||||
for i, s in enumerate(["volts", "amps", "meters per second", "", "km per hour", "meters", "degrees", "percent", "milliamps"]):
|
||||
generate(s, 50+i)
|
||||
systemSounds.extend(generate(s, 40+i))
|
||||
for i, s in enumerate(["volts", "amps", "meters per second", "", "km per hour", "meters", "degrees", "percent", "milliamps", "milliamps per hour", "watts", "", "feet", "knots"]):
|
||||
systemSounds.extend(generate(s, 50+i))
|
||||
|
||||
elif "fr" in sys.argv:
|
||||
if "sapi" in sys.argv:
|
||||
tts.SetVoiceByName("ScanSoftVirginie_Full_22kHz")
|
||||
voice = "french"
|
||||
for i in range(20):
|
||||
systemSounds.extend(generate(str(i), i))
|
||||
for i in range(20, 100, 10):
|
||||
systemSounds.extend(generate(str(i), 20+(i-20)/10))
|
||||
systemSounds.extend(generate("cent", 28))
|
||||
systemSounds.extend(generate("mille", 29))
|
||||
for i, s in enumerate(["heure", "minute", "seconde", "", "", "", "", "et", "moins"]):
|
||||
systemSounds.extend(generate(s, 40+i))
|
||||
|
||||
for i, s in enumerate(["timer", "", "tension", "tension", "émission", u"réception", "altitude", "moteur",
|
||||
"essence", u"température", "température", "vitesse", "distance", "altitude", "élément lipo",
|
||||
"total lipo", "tension", "courant", "consommation", "puissance", "accelération X", "accelération Y", "accelération Z",
|
||||
"orientation", "vario"]):
|
||||
systemSounds.extend(generate(s, 101+i))
|
||||
for i, s in enumerate(["volts", u"ampères", u"mètres seconde", "", "km heure", u"mètres", u"degrés", "pourcents", u"milli ampères", u"milli ampères / heure", "watt", "", "pieds", "knotts"]):
|
||||
systemSounds.extend(generate(s, 50+i))
|
||||
for s, f in [(u"train rentré", "gearup"),
|
||||
(u"train sorti", "geardn"),
|
||||
(u"volets rentrés", "flapup"),
|
||||
(u"volets sortis", "flapdn"),
|
||||
(u"atterrissage", "attero"),
|
||||
(u"écolage", "trnon"),
|
||||
(u"fin écolage", "trnoff"),
|
||||
(u"moteur coupé", "engoff"),
|
||||
]:
|
||||
sounds.extend(generate(s, f))
|
||||
|
||||
if "zip" in sys.argv:
|
||||
zip_name = voice + ".zip"
|
||||
zip = zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED)
|
||||
for f in systemSounds:
|
||||
zip.write(f, "9XSOUNDS/SYSTEM/" + f)
|
||||
os.remove(f)
|
||||
for f in sounds:
|
||||
zip.write(f, "9XSOUNDS/" + f)
|
||||
os.remove(f)
|
||||
zip.close()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue