Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Created January 9, 2020 02:22
Show Gist options
  • Save RicherMans/d6c6f8c6d1742d71b40939be543e441f to your computer and use it in GitHub Desktop.
Save RicherMans/d6c6f8c6d1742d71b40939be543e441f to your computer and use it in GitHub Desktop.
download_audio.sh
# @Author: richman
# @Date: 2018-03-15
# @Last Modified by: richman
# @Last Modified time: 2018-03-30
if [[ $# < 1 ]]; then
echo "Input .csv file .e.g balanced_train_segments.csv"
exit
fi
inp=$1
njobs=${2:-4}
SAMPLE_RATE=16000
fetch_clip() {
echo $1
# echo "Fetching $1 ($2 to $3)..."
outname="$1_$2_$3"
if [ -f "${outname}*" ]; then
# echo "Already have it."
return
fi
youtube-dl https://youtube.com/watch?v=$1 \
--quiet --extract-audio --audio-format flac --no-warnings --output "$outname.%(ext)s"
if [ $? -eq 0 ]; then
downloaded_file=$(find . -name "$outname*")
ffmpeg -loglevel quiet -i "$downloaded_file" -ar $SAMPLE_RATE \
-ss "$2" -to "$3" "./${outname}_out.flac"
mv "./${outname}_out.flac" "./${outname}.flac"
fi
}
export SAMPLE_RATE
export -f fetch_clip
grep "^[^#;]" $inp | parallel --resume --joblog job.log --bar -j $njobs --colsep=, fetch_clip {1} {2} {3} > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment