# for VoiceOver, make sure you have already installed svox TTS softwave def voice_path_func(text, lang): tmp_file = tempfile.NamedTemporaryFile(delete=False) tmp_file_name = tmp_file.name + '.wav' tmp_file.close() cmd = 'pico2wave --wave={} --lang={} {}'.format(tmp_file_name, lang, repr(text)) # print('\n\n', cmd, '\n') os.system(cmd) return tmp_file_name base = '/media/data/ipod_base_doc_text' ipod = Shuffle(base) ipod.playlists.clear() # enable VoiceOver ipod.enable_voiceover = True # when track or playlist set "voice = 'text', 'lang code'", will call this funcition ipod.voice_path_func = voice_path_func # create a master playlist, it's the "All songs" in ipod master_playlist = ipod.playlists.append_one(pl_type=MASTER) # create a normal playlist
def sync(args): src = os.path.realpath(args.src) base = os.path.realpath(args.base) ipod = Shuffle(base) if ipod.enable_voiceover: local_voicedb = LocalVoiceDB( os.path.join(CACHE_DIR, 'voices_log.json'), os.path.join(CACHE_DIR, 'voices')) local_voicedb.clean() classify_tts_lang_func, local_voice_path_func = voice_things( local_voicedb, args) ipod.voice_path_func = local_voice_path_func ipod.audiodb.clean() ipod.tracks_voiceoverdb.clean() ipod.playlists_voiceoverdb.clean() ipod.playlists.clear() local_filelog = LocalFileLog(os.path.join(CACHE_DIR, 'local_file_log.json')) def set_voice(obj, text, lang): try: obj.voice = text, lang except GetVoiceDataError as e: log('{}, ignornd.'.format(e)) def add_files_to_playlist(pl, files, get_track_voice_title=None): for file in files: checksum = local_filelog.get_checksum(file) if not checksum: local_filelog.log_it(file) checksum = local_filelog.get_checksum(file) path_in_ipod = ipod.audiodb.get_filename(checksum) if not path_in_ipod: ipod.audiodb.add(file) path_in_ipod = ipod.audiodb.get_filename(checksum) track = ipod.create_track(path_in_ipod) pl.tracks.append(track) if ipod.enable_voiceover: text = get_track_voice_title(file) lang = classify_tts_lang_func(text) set_voice(track, text, lang) def add_playlists(title_and_files, pl_type, text_fun): for title, files in title_and_files: pl = ipod.create_playlist(pl_type) ipod.playlists.append(pl) if ipod.enable_voiceover: lang = classify_tts_lang_func(title) set_voice(pl, title, lang) add_files_to_playlist(pl, files, text_fun) def exists_and_isdir(path): return True if os.path.exists(path) and os.path.isdir(path) else False normal_dir = os.path.join(src, 'music') podcasts_dir = os.path.join(src, 'podcasts') audiobooks_dir = os.path.join(src, 'audiobooks') if exists_and_isdir(normal_dir): master_audio, normals = get_normals2(normal_dir) if master_audio: master_pl = ipod.playlists.append_one(pl_type=MASTER) add_files_to_playlist(master_pl, master_audio, title_artist_or_filename) if normals: add_playlists(normals, NORMAL, title_artist_or_filename) if exists_and_isdir(podcasts_dir): podcasts = get_podcasts(podcasts_dir) if podcasts: add_playlists(podcasts, PODCAST, title_artist_or_filename) if exists_and_isdir(audiobooks_dir): audiobooks = get_audiobooks(audiobooks_dir) if audiobooks: add_playlists(audiobooks, AUDIOBOOK, filename) ipod.write_db()
def sync(args): src = os.path.realpath(args.src) base = os.path.realpath(args.base) ipod = Shuffle(base) if ipod.enable_voiceover: local_voicedb = LocalVoiceDB(os.path.join(CACHE_DIR, 'voices_log.json'), os.path.join(CACHE_DIR, 'voices')) local_voicedb.clean() classify_tts_lang_func, local_voice_path_func = voice_things(local_voicedb, args) ipod.voice_path_func = local_voice_path_func ipod.audiodb.clean() ipod.tracks_voiceoverdb.clean() ipod.playlists_voiceoverdb.clean() ipod.playlists.clear() local_filelog = LocalFileLog(os.path.join(CACHE_DIR, 'local_file_log.json')) def set_voice(obj, text, lang): try: obj.voice = text, lang except GetVoiceDataError as e: log('{}, ignornd.'.format(e)) def add_files_to_playlist(pl, files, get_track_voice_title=None): for file in files: checksum = local_filelog.get_checksum(file) if not checksum: local_filelog.log_it(file) checksum = local_filelog.get_checksum(file) path_in_ipod = ipod.audiodb.get_filename(checksum) if not path_in_ipod: ipod.audiodb.add(file) path_in_ipod = ipod.audiodb.get_filename(checksum) track = ipod.create_track(path_in_ipod) pl.tracks.append(track) if ipod.enable_voiceover: text = get_track_voice_title(file) lang = classify_tts_lang_func(text) set_voice(track, text, lang) def add_playlists(title_and_files, pl_type, text_fun): for title, files in title_and_files: pl = ipod.create_playlist(pl_type) ipod.playlists.append(pl) if ipod.enable_voiceover: lang = classify_tts_lang_func(title) set_voice(pl, title, lang) add_files_to_playlist(pl, files, text_fun) def exists_and_isdir(path): return True if os.path.exists(path) and os.path.isdir(path) else False normal_dir = os.path.join(src, 'music') podcasts_dir = os.path.join(src, 'podcasts') audiobooks_dir = os.path.join(src, 'audiobooks') if exists_and_isdir(normal_dir): master_audio, normals = get_normals2(normal_dir) if master_audio: master_pl = ipod.playlists.append_one(pl_type=MASTER) add_files_to_playlist(master_pl, master_audio, title_artist_or_filename) if normals: add_playlists(normals, NORMAL, title_artist_or_filename) if exists_and_isdir(podcasts_dir): podcasts = get_podcasts(podcasts_dir) if podcasts: add_playlists(podcasts, PODCAST, title_artist_or_filename) if exists_and_isdir(audiobooks_dir): audiobooks = get_audiobooks(audiobooks_dir) if audiobooks: add_playlists(audiobooks, AUDIOBOOK, filename) ipod.write_db()