Added standalone script

This commit is contained in:
Samuel Ortion 2021-05-01 10:40:48 +02:00
parent 833b2835be
commit dba258bfcb
4 changed files with 150 additions and 22 deletions

View File

@ -1,3 +1,41 @@
# time-expanseR
Convert .WAV in real time into .WAV in time expansion x10 using warbleR R package.
Convert .WAV in real time into .WAV in time expansion x10 using warbleR R package.
## Installation
### Requirements
```bash
apt install -y r-base cmake libcurl4-openssl-dev libfftw3-*
```
### R packages
```bash
R
```
```R
install.packages("warbleR")
```
### Scripts
```bash
git clone http://localhost:3400/Chiro-Canto/time-expanseR.git
```
```bash
chmod +x expanseR.sh
chmod +x split_5s.sh
chmod +x expansion_x10.R
```
## Usage
```bash
chmod +x expanseR
```
```
bash expanseR -o /path/to/your/input/directory -i /path/to/your/output/directory
```
You can also use R script in standalone, you will have to specify you folders in the r script.

43
expanseR.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
function usage {
printf "./$(basename $0) -h - - shows help \n"
printf "./$(basename $0) -i input_dir -o output_dir - - convert wav in real time into wav in time expansion x10 \n"
}
optstring=":hi:o:"
# Defaults
indir="raw"
outdir="exp"
while getopts ${optstring} arg
do
case "${arg}" in
h)
printf "$(basename $0) usage: \n"
usage
;;
i)
indir="${OPTARG}"
echo "indir: $indir"
;;
o)
outdir="${OPTARG}"
echo "outdir: $outdir"
;;
:)
echo "$0: Must supply an argument to -$OPTARG."
exit 1
;;
?)
echo "Invalid option: -${OPTARG}."
echo
usage
;;
esac
done
splitdir=$(sed "s/raw/split/g" <<< $indir)
bash split_5s.sh -i $indir -o $splitdir
exit 0

View File

@ -1,11 +1,18 @@
#!/usr/bin/Rscrypt
library(warbleR)
library(tuneR)
# Set the inputs directory
dir = "/home/ortion/records/"
indir = paste0(dir, 'raw')
indir = paste0(dir, 'split')
outdir = paste0(dir, 'exp')
# Get user options
indir = getOptions(option.object, "i")
outdir = getOptions(option.object, "o")
print(indir, outdir)
# Set name prefix
car = "721035"
year = 2021

View File

@ -3,31 +3,71 @@
##########################################################
#
# Split wav sounds into 5s wav using ffmpeg
#
# Samuel ORTION
##########################################################
indir="/home/ortion/Documents/projects/time-expanseR/media/raw"
outdir="/home/ortion/Documents/projects/time-expanseR/media/split"
function usage {
printf "./$(basename $0) -h - - shows help \n"
printf "./$(basename $0) -i input_dir -o output_dir - - split long wav into wav 5s wav \n"
}
function split {
cd $indir
for item in `ls ./*.WAV`
do
audio_dur=`sox --i -D $item`
# Convert float to int
audio_dur=${audio_dur%.*}
echo "$item ($audio_dur)"
ss=0
to=5
for ss in `seq 0 5 $(( $audio_dur - 5 ))`
do
to=$(( $ss + 5 ))
echo "Spliting $item ($ss/$audio_dur)"
ffmpeg -ss $ss -i "$indir/$item" -t $to -c copy "$outdir/$item-$ss.wav"
done
done
}
optstring=":hi:o:"
# Defaults
indir="raw"
outdir="split"
while getopts ${optstring} arg
do
case "${arg}" in
h)
printf "$(basename $0) usage: \n"
usage
;;
i)
indir="${OPTARG}"
# echo "indir: $indir"
;;
o)
outdir="${OPTARG}"
# echo "outdir: $outdir"
;;
:)
echo "$0: Must supply an argument to -$OPTARG."
exit 1
;;
?)
echo "Invalid option: -${OPTARG}."
echo
usage
;;
esac
done
if [ ! -d $outdir ];
then
mkdir $outdir
fi
cd $indir
split
for item in `ls ./*.WAV`
do
audio_dur=`sox --i -D $item`
# Convert float to int
audio_dur=${audio_dur%.*}
echo "$item ($audio_dur)"
ss=0
to=5
for ss in `seq 0 5 $(( $audio_dur - 5 ))`
do
to=$(( $ss + 5 ))
echo $ss $to
ffmpeg -ss $ss -i "$indir/$item" -t $to -c copy "$outdir/$item-$ss.wav"
done
done