#!/bin/bash # Base dataset folder BASE_DIR="audio_data" CHUNK_SIZE=2000 # number of files per tar shard # Function to shard a split shard_split () { SPLIT=$1 echo "Sharding $SPLIT..." cd "$BASE_DIR/$SPLIT" || exit 1 # Create chunks with relative paths ls -1 | split -l $CHUNK_SIZE - "${SPLIT}_chunk_" # Loop over chunks and create tar.gz archives for chunk in ${SPLIT}_chunk_*; do shard_name="${SPLIT}_${chunk##*_}.tar.gz" # Only include files that exist (avoid empty tar) files=$(cat "$chunk") if [ -z "$files" ]; then echo "Skipping empty chunk $chunk" continue fi tar -czf "$shard_name" --no-recursion $files echo "Created $shard_name with $(wc -l < $chunk) files" # Remove the chunk file rm "$chunk" done cd - > /dev/null } # Shard all splits for split in train validation test; do shard_split "$split" done echo "All splits have been tarred successfully!"