Added all in one python script that convert in Tadarida format
This commit is contained in:
parent
2b16b8004c
commit
e62a9fd140
21
split_5s.sh
21
split_5s.sh
@ -8,12 +8,11 @@
|
|||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
printf "./$(basename $0) -h - - shows help \n"
|
printf "./$(basename $0) -h - - shows help \n"
|
||||||
printf "./$(basename $0) -i input_dir -o output_dir - - split long wav into wav 5s wav \n"
|
printf "./$(basename $0) -i input_dir -o output_dir - - split long wav into 5s wav \n"
|
||||||
}
|
}
|
||||||
|
|
||||||
function split {
|
function split {
|
||||||
cd $indir
|
for item in `ls $indir/*.WAV`
|
||||||
for item in `ls ./*.WAV`
|
|
||||||
do
|
do
|
||||||
audio_dur=`sox --i -D $item`
|
audio_dur=`sox --i -D $item`
|
||||||
# Convert float to int
|
# Convert float to int
|
||||||
@ -25,12 +24,11 @@ function split {
|
|||||||
do
|
do
|
||||||
to=$(( $ss + 5 ))
|
to=$(( $ss + 5 ))
|
||||||
echo "Spliting $item ($ss/$audio_dur)"
|
echo "Spliting $item ($ss/$audio_dur)"
|
||||||
ffmpeg -ss $ss -i "$indir/$item" -t $to -c copy "$outdir/$item-$ss.wav"
|
ffmpeg -ss $ss -i $indir/`basename $item` -t $to -c copy $outdir/`basename $item`-$ss.wav
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
optstring=":hi:o:"
|
optstring=":hi:o:"
|
||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
@ -41,29 +39,30 @@ while getopts ${optstring} arg
|
|||||||
do
|
do
|
||||||
case "${arg}" in
|
case "${arg}" in
|
||||||
h)
|
h)
|
||||||
printf "$(basename $0) usage: \n"
|
printf "$( basename $0 ) usage: \n"
|
||||||
usage
|
usage
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
indir="${OPTARG}"
|
indir="${OPTARG}"
|
||||||
# echo "indir: $indir"
|
echo "indir: $indir"
|
||||||
;;
|
;;
|
||||||
o)
|
o)
|
||||||
outdir="${OPTARG}"
|
outdir="${OPTARG}"
|
||||||
# echo "outdir: $outdir"
|
echo "outdir: $outdir"
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
echo "$0: Must supply an argument to -$OPTARG."
|
echo "$( basename $0 ): Must supply an argument to -$OPTARG."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
?)
|
?)
|
||||||
echo "Invalid option: -${OPTARG}."
|
echo "Invalid option: -${arg}."
|
||||||
echo
|
echo
|
||||||
usage
|
usage
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ! -d $outdir ];
|
if [ ! -d $outdir ];
|
||||||
then
|
then
|
||||||
mkdir $outdir
|
mkdir $outdir
|
||||||
|
24
tadarida_preprocessing.py
Executable file
24
tadarida_preprocessing.py
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import soundfile as sf
|
||||||
|
|
||||||
|
def exp_rate(insoundfile, outsoundfile, rate_ratio):
|
||||||
|
data, samplerate = sf.read(insoundfile)
|
||||||
|
new_samplerate = int(samplerate * rate_ratio)
|
||||||
|
sf.write(outsoundfile, data, new_samplerate)
|
||||||
|
|
||||||
|
vigie_prefix = "Car721035-2021-Pass0-Z2"
|
||||||
|
device_prefix = "-AudioMoth-247AA5015FDF286B-"
|
||||||
|
prefix = vigie_prefix + device_prefix
|
||||||
|
|
||||||
|
indir = "raw"
|
||||||
|
outdir = "exp"
|
||||||
|
|
||||||
|
files = os.listdir(indir)
|
||||||
|
|
||||||
|
for wav in files:
|
||||||
|
insoundfile = os.path.join(indir, wav)
|
||||||
|
outsoundfile = os.path.join(outdir, prefix + wav)
|
||||||
|
exp_rate(insoundfile, outsoundfile, 0.1)
|
||||||
|
os.system('split_5s -i exp -o split')
|
Loading…
Reference in New Issue
Block a user