mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 09:15:38 +03:00
tts.py compatibility with espeak
This commit is contained in:
parent
25e980e231
commit
1953eb4cfe
1 changed files with 18 additions and 16 deletions
34
util/tts.py
34
util/tts.py
|
@ -25,19 +25,24 @@ import os, sys, shutil, platform, subprocess, wave, zipfile
|
||||||
def generate(str, idx):
|
def generate(str, idx):
|
||||||
result = None
|
result = None
|
||||||
if str and platform.system() == "Windows":
|
if str and platform.system() == "Windows":
|
||||||
if "sapi" in sys.argv:
|
if "speak" in sys.argv:
|
||||||
if "speak" in sys.argv:
|
if "sapi" in sys.argv:
|
||||||
tts.Speak(str)
|
tts.Speak(str)
|
||||||
else:
|
else:
|
||||||
if isinstance(idx, int):
|
# TODO speak from espeak, possible?
|
||||||
result = "%04d.wav" % idx
|
subprocess.Popen(["espeak.exe", "-z", "-w", "%04d.wav" % idx, str], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||||
else:
|
else:
|
||||||
result = idx + ".wav"
|
if isinstance(idx, int):
|
||||||
print result, str
|
result = "%04d.wav" % idx
|
||||||
|
else:
|
||||||
|
result = idx + ".wav"
|
||||||
|
|
||||||
|
print result, str
|
||||||
|
|
||||||
|
if "sapi" in sys.argv:
|
||||||
temp = "_" + result
|
temp = "_" + result
|
||||||
tts.SpeakToWave(temp, str)
|
tts.SpeakToWave(temp, str)
|
||||||
|
# we remove empty frames at start and end of the file
|
||||||
i = wave.open(temp, "r")
|
i = wave.open(temp, "r")
|
||||||
n = i.getnframes()
|
n = i.getnframes()
|
||||||
f = i.readframes(n)
|
f = i.readframes(n)
|
||||||
|
@ -47,14 +52,11 @@ def generate(str, idx):
|
||||||
o.setsampwidth(i.getsampwidth())
|
o.setsampwidth(i.getsampwidth())
|
||||||
o.setframerate(i.getframerate())
|
o.setframerate(i.getframerate())
|
||||||
o.writeframes(f[6400:-6400])
|
o.writeframes(f[6400:-6400])
|
||||||
o.close()
|
o.close()
|
||||||
|
os.remove(temp)
|
||||||
os.remove(temp)
|
else:
|
||||||
|
subprocess.Popen(["espeak.exe", "-z", "-w", result, str], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||||
else:
|
|
||||||
subprocess.Popen(["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:
|
if 'ad4' in sys.argv:
|
||||||
subprocess.Popen(["AD4CONVERTER.EXE", "-E4", result], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
subprocess.Popen(["AD4CONVERTER.EXE", "-E4", result], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||||
result = result.replace(".wav", ".ad4")
|
result = result.replace(".wav", ".ad4")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue