Late binding of opuslib, nicer progress bars on export

This commit is contained in:
Tilman Kamp 2020-02-13 12:21:25 +01:00
Родитель dfc565190d
Коммит 42556e1988
2 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -2,7 +2,6 @@ import os
import io
import sox
import wave
import opuslib
import tempfile
import collections
import numpy as np
@ -268,6 +267,7 @@ def get_opus_frame_size(rate):
def write_opus(opus_file, audio_format, audio_data):
rate, channels, width = audio_format
frame_size = get_opus_frame_size(rate)
import opuslib
encoder = opuslib.Encoder(rate, channels, opuslib.APPLICATION_AUDIO)
chunk_size = frame_size * channels * width
opus_file.write(pack_number(len(audio_data), OPUS_PCM_LEN_SIZE))
@ -296,6 +296,7 @@ def read_opus(opus_file):
pcm_buffer_size, audio_format = read_opus_header(opus_file)
rate, channels, _ = audio_format
frame_size = get_opus_frame_size(rate)
import opuslib
decoder = opuslib.Decoder(rate, channels)
audio_data = bytearray()
while len(audio_data) < pcm_buffer_size:

Просмотреть файл

@ -166,7 +166,7 @@ def main(args):
logging.getLogger('sox').setLevel(logging.ERROR)
def progress(it=None, desc='Processing', total=None):
desc = desc.rjust(24)
desc = desc.rjust(30)
return iter if args.no_progress else tqdm(it, desc=desc, total=total, ncols=120)
logging.debug("Start")
@ -414,8 +414,8 @@ def main(args):
sdb = lists[list_name]
sdb.add(sample)
if not dry_run:
for sdb in lists.values():
with progress(desc='Finalizing SDB "{}"'.format(sdb.sdb_filename), total=1000) as bar:
for list_name, sdb in lists.items():
with progress(desc='Finalizing "{}.sdb"'.format(list_name), total=1000) as bar:
for frac in sdb.finalize():
bar.n = int(frac * 1001)
bar.refresh()