time-expanseR/tadarida_preprocessing.py

25 lines
624 B
Python
Executable File

#!/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')