This commit is contained in:
GijsTimmers 2022-10-16 01:15:36 +02:00 committed by GitHub
commit 9eb0a0fe18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,7 +97,7 @@ def group_tracks_by_id3_template(tracks, template):
return sorted(grouped_tracks_dict.items())
class Text2Speech(object):
valid_tts = {'pico2wave': True, 'RHVoice': True, 'espeak': True, 'say': True}
valid_tts = {'pico2wave': True, 'RHVoice': True, 'espeak': True, 'say': True, 'gtts': True}
@staticmethod
def check_support():
@ -124,6 +124,14 @@ class Text2Speech(object):
else:
voiceoverAvailable = True
# Check for gtts-cli voiceover
# https://github.com/pndurette/gTTS
if not exec_exists_in_path("gtts-cli"):
Text2Speech.valid_tts['gtts-cli'] = False
print("Warning: gtts-cli not found, voicever won't be generated using it.")
else:
voiceoverAvailable = True
# Check for Russian RHVoice voiceover
if not exec_exists_in_path("RHVoice"):
Text2Speech.valid_tts['RHVoice'] = False
@ -156,6 +164,8 @@ class Text2Speech(object):
return True
elif Text2Speech.say(out_wav_path, text):
return True
elif Text2Speech.gtts(out_wav_path, text):
return True
else:
return False
@ -181,6 +191,19 @@ class Text2Speech(object):
subprocess.call(["say", "-o", out_wav_path, '--data-format=LEI16', '--file-format=WAVE', '--', unicodetext])
return True
@staticmethod
def gtts(out_wav_path, unicodetext):
if not Text2Speech.valid_tts['gtts']:
return False
tmp_mp3_file = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
tmp_mp3_file.close()
tmp_wav_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
tmp_wav_file.close()
subprocess.call(["gtts-cli", "--lang", "en", unicodetext, "--output", tmp_mp3_file.name])
subprocess.call(["ffmpeg", "-y", "-loglevel", "error", "-hide_banner", "-nostats", "-i", tmp_mp3_file.name, tmp_wav_file.name])
subprocess.call(["mv", tmp_wav_file.name, out_wav_path])
return True
@staticmethod
def espeak(out_wav_path, unicodetext):
if not Text2Speech.valid_tts['espeak']: