mirror of
https://github.com/nims11/IPod-Shuffle-4g.git
synced 2025-12-07 16:08:00 +09:00
mockup for gtts support
This commit is contained in:
parent
a97a99ab86
commit
ed831fe85b
1 changed files with 24 additions and 1 deletions
|
|
@ -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']:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue