File size: 1,281 Bytes
0534124 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #!/bin/bash
set -euo pipefail
INPUT=./lhotseWorkspace/final_fixed.jsonl.gz
OUTDIR=~/shar_data_set_v67
SHARD_SIZE=2000
# Count total cuts so we can render a progress bar.
echo "Counting cuts in $INPUT ..."
TOTAL=$(zcat "$INPUT" | wc -l)
echo "Total cuts: $TOTAL"
progress_bar() {
local done=$1 total=$2 width=40
local pct=0
(( total > 0 )) && pct=$(( done * 100 / total ))
local filled=$(( pct * width / 100 ))
local bar
bar=$(printf '%*s' "$filled" '' | tr ' ' '#')
bar=$bar$(printf '%*s' "$(( width - filled ))" '')
printf '\r[%s] %3d%% (%d/%d cuts)' "$bar" "$pct" "$done" "$total"
}
# Background watcher: each completed shard holds SHARD_SIZE cuts.
mkdir -p "$OUTDIR"
(
while true; do
shards=$(find "$OUTDIR" -maxdepth 1 -name 'cuts.*.jsonl.gz' 2>/dev/null | wc -l)
done=$(( shards * SHARD_SIZE ))
(( done > TOTAL )) && done=$TOTAL
progress_bar "$done" "$TOTAL"
(( done >= TOTAL )) && break
sleep 2
done
) &
WATCHER=$!
LHOTSE_AUDIO_BACKEND=LibsndfileBackend lhotse shar export -j 4 --fault-tolerant --shard-size "$SHARD_SIZE" -vvv --audio opus "$INPUT" "$OUTDIR"
kill "$WATCHER" 2>/dev/null || true
wait "$WATCHER" 2>/dev/null || true
progress_bar "$TOTAL" "$TOTAL"
printf '\nDone.\n'
|