Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mockup for gTTS support (see #59) #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion ipod-shuffle-4g.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -124,6 +124,14 @@ def check_support():
else:
voiceoverAvailable = True

# Check for gtts-cli voiceover
# https://github.com/pndurette/gTTS
if not exec_exists_in_path("gtts-cli"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, we need to check for ffmpeg here as well, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we also need to check for sox of rhvoice? This is not related to this PR, but I just found this there as well.

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
Expand Down Expand Up @@ -156,6 +164,8 @@ def text2speech(out_wav_path, text):
return True
elif Text2Speech.say(out_wav_path, text):
return True
elif Text2Speech.gtts(out_wav_path, text):
return True
else:
return False

Expand All @@ -181,6 +191,19 @@ def say(out_wav_path, unicodetext):
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']:
Expand Down