Skip to content

Instantly share code, notes, and snippets.

@seungwonpark
Last active March 11, 2020 10:41
Show Gist options
  • Save seungwonpark/a60505b4529d800d9b0a1fe7d5f2456c to your computer and use it in GitHub Desktop.
Save seungwonpark/a60505b4529d800d9b0a1fe7d5f2456c to your computer and use it in GitHub Desktop.
# copy this to root directory of data and ./resample_delete.sh
# ffmpeg required
# https://unix.stackexchange.com/questions/103920/parallelize-a-bash-for-loop
open_sem(){
mkfifo pipe-$$
exec 3<>pipe-$$
rm pipe-$$
local i=$1
for((;i>0;i--)); do
printf %s 000 >&3
done
}
run_with_lock(){
local x
read -u 3 -n 3 x && ((0==x)) || exit $x
(
( "$@"; )
printf '%.3d' $? >&3
)&
}
resample_delete(){
echo $1
ffmpeg -loglevel panic -i "$1" -ar 8000 "${1%.*}-8k.wav"
rm $1
}
N=32
open_sem $N
for f in $(find . -name "*.wav"); do
run_with_lock resample_delete "$f"
done
@seungwonpark
Copy link
Author

find . -name '*-16k.wav' -exec bash -c 'mv $0 ${0/-16k/}' {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment