xyz / command.bash
benderrodriguez's picture
Upload folder using huggingface_hub
0534124 verified
Raw
History Blame Contribute Delete
1.28 kB
#!/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'