support for using "say" to generate voiceover files

This commit is contained in:
Arno Hautala 2021-08-24 22:46:05 -04:00
parent 589a0cd251
commit 8863026157

View file

@ -97,12 +97,19 @@ def group_tracks_by_id3_template(tracks, template):
return sorted(grouped_tracks_dict.items()) return sorted(grouped_tracks_dict.items())
class Text2Speech(object): class Text2Speech(object):
valid_tts = {'pico2wave': True, 'RHVoice': True, 'espeak': True} valid_tts = {'pico2wave': True, 'RHVoice': True, 'espeak': True, 'say': True}
@staticmethod @staticmethod
def check_support(): def check_support():
voiceoverAvailable = False voiceoverAvailable = False
# Check for say voiceover
if not exec_exists_in_path("say"):
Text2Speech.valid_tts['say'] = False
print("Warning: say not found, voicever won't be generated using it.")
else:
voiceoverAvailable = True
# Check for pico2wave voiceover # Check for pico2wave voiceover
if not exec_exists_in_path("pico2wave"): if not exec_exists_in_path("pico2wave"):
Text2Speech.valid_tts['pico2wave'] = False Text2Speech.valid_tts['pico2wave'] = False
@ -147,6 +154,8 @@ class Text2Speech(object):
return True return True
elif Text2Speech.espeak(out_wav_path, text): elif Text2Speech.espeak(out_wav_path, text):
return True return True
elif Text2Speech.say(out_wav_path, text):
return True
else: else:
return False return False
@ -165,6 +174,13 @@ class Text2Speech(object):
subprocess.call(["pico2wave", "-l", "en-GB", "-w", out_wav_path, unicodetext]) subprocess.call(["pico2wave", "-l", "en-GB", "-w", out_wav_path, unicodetext])
return True return True
@staticmethod
def say(out_wav_path, unicodetext):
if not Text2Speech.valid_tts['say']:
return False
subprocess.call(["say", "-o", out_wav_path, '--data-format=LEI16', '--file-format=WAVE', unicodetext])
return True
@staticmethod @staticmethod
def espeak(out_wav_path, unicodetext): def espeak(out_wav_path, unicodetext):
if not Text2Speech.valid_tts['espeak']: if not Text2Speech.valid_tts['espeak']:
@ -464,7 +480,7 @@ class Playlist(Record):
def set_master(self, tracks): def set_master(self, tracks):
# By default use "All Songs" builtin voiceover (dbid all zero) # By default use "All Songs" builtin voiceover (dbid all zero)
# Else generate alternative "All Songs" to fit the speaker voice of other playlists # Else generate alternative "All Songs" to fit the speaker voice of other playlists
if self.playlist_voiceover and (Text2Speech.valid_tts['pico2wave'] or Text2Speech.valid_tts['espeak']): if self.playlist_voiceover and (Text2Speech.valid_tts['pico2wave'] or Text2Speech.valid_tts['espeak'] or Text2Speech.valid_tts['say']):
self["dbid"] = hashlib.md5(b"masterlist").digest()[:8] self["dbid"] = hashlib.md5(b"masterlist").digest()[:8]
self.text_to_speech("All songs", self["dbid"], True) self.text_to_speech("All songs", self["dbid"], True)
self["listtype"] = 1 self["listtype"] = 1