Exemple #1
0
def _output(echo):
    with open(config['sequence'], 'r') as f:
        sections, total_dur = sequence.parse(f.readlines())
    if len(sections) == 0:
        raise ValueError('no sections')

    time_off = 0
    i = 0
    if len(sys.argv) == 2:
        sec_name = sys.argv[1]
        for i, s in enumerate(sections):
            if sec_name == s.name:
                time_off = s.start
                break
        else:
            raise ValueError('no such section %s' % sec_name)

        sections = sections[i:]
        for s in sections:
            s.start -= time_off

    for i, s in enumerate(sections[:-1]):
        echo(i + 1, s, sections[i + 1], sections[i + 1].start)
    echo(len(sections), sections[-1], None,
         audio_slice.audio_len(config['bgm']))
Exemple #2
0
def find_range(begin_sec_name, end_sec_name):
    with open(config['sequence'], 'r') as f:
        sections, total_dur = sequence.parse(f.readlines(), True)
    begin_index, begin_section = _find_sec(sections, begin_sec_name)
    begin_time = begin_section.start
    end_time, sec_range = _interval_secs(sections, end_sec_name, begin_index)
    return begin_time, end_time, sec_range
Exemple #3
0
def split(input_file, sequence_file):
    duration = audio_len(input_file)
    with open(sequence_file, 'r') as f:
        sections = sequence.parse(f.readlines())[0]
    pathname, ext = os.path.splitext(input_file)
    name = os.path.basename(pathname)
    last_sec = sections[0]
    for sec in sections[1:]:
        if sec.start == last_sec.start:
            continue
        if sec.start < last_sec.start:
            raise ValueError('Section start time error: %s < %s' %
                             (sec.name, last_sec.name))
        if duration < sec.start:
            raise ValueError('Exceed audio duration ' + (sec.start))
        _audio_from_to(input_file, name, ext, last_sec.start, sec.start,
                       OUTPUT_DIR)
        last_sec = sec
    if duration == last_sec.start:
        return
    _audio_from_to(input_file, name, ext, last_sec.start, duration,
                   OUTPUT_DIR)