Exemplo n.º 1
0
def export_adlib_sounds(params, cfg, zip_file, audio_chunks_handler):
    logger = logging.getLogger()
    logger.info('Exporting AdLib sounds')

    start, count = cfg.AUDIO_PARTITIONS_MAP['adlib']
    adlib_manager = pywolf.audio.AdLibSoundManager(audio_chunks_handler, start, count)

    for i, sound in enumerate(adlib_manager):
        name = cfg.ADLIB_SOUND_NAMES[i]
        path = 'sound/{}/adlib/{}.wav'.format(params.short_name, name)
        logger.info('AdLib sound [%d/%d]: %r', (i + 1), count, path)
        imf_chunk = sound.to_imf_chunk()
        wave_path = convert_imf_to_wave(imf_chunk, params.imf2wav_path,
                                        wave_rate=params.wave_rate, imf_rate=params.imf_rate)
        try:
            with open(wave_path, 'rb') as wave_file:
                wave_samples = wave_file.read()
            zip_file.writestr(path, wave_samples)
        finally:
            try:
                os.unlink(wave_path)
            except:
                pass

    logger.info('Done')
    _sep()
Exemplo n.º 2
0
def export_musics(params, cfg, zip_file, audio_chunks_handler):
    logger = logging.getLogger()
    logger.info('Exporting musics')

    start, count = cfg.AUDIO_PARTITIONS_MAP['music']

    for i in range(count):
        chunk_index = start + i
        name = cfg.MUSIC_NAMES[i]
        path = 'music/{}/{}.wav'.format(params.short_name, name)
        logger.info('Music [%d/%d]: %r', (i + 1), count, path)
        imf_chunk = audio_chunks_handler[chunk_index]
        wave_path = convert_imf_to_wave(imf_chunk, params.imf2wav_path,
                                        wave_rate=params.wave_rate, imf_rate=params.imf_rate)
        try:
            with open(wave_path, 'rb') as wave_file:
                wave_samples = wave_file.read()
            zip_file.writestr(path, wave_samples)
        finally:
            try:
                os.unlink(wave_path)
            except:
                pass

    logger.info('Done')
    _sep()