From dba258bfcbcd6ebb068146a388a5ced1074126d8 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Sat, 1 May 2021 10:40:48 +0200 Subject: [PATCH] Added standalone script --- README.md | 40 ++++++++++++++++++++++++- expanseR.sh | 43 +++++++++++++++++++++++++++ expansion_x10.R | 11 +++++-- split_5s.sh | 78 +++++++++++++++++++++++++++++++++++++------------ 4 files changed, 150 insertions(+), 22 deletions(-) create mode 100755 expanseR.sh diff --git a/README.md b/README.md index ce4b37e..5566bea 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # time-expanseR -Convert .WAV in real time into .WAV in time expansion x10 using warbleR R package. \ No newline at end of file +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. \ No newline at end of file diff --git a/expanseR.sh b/expanseR.sh new file mode 100755 index 0000000..135653e --- /dev/null +++ b/expanseR.sh @@ -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 diff --git a/expansion_x10.R b/expansion_x10.R index d39376a..a358f6a 100644 --- a/expansion_x10.R +++ b/expansion_x10.R @@ -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 diff --git a/split_5s.sh b/split_5s.sh index 6097080..ba3b4ca 100755 --- a/split_5s.sh +++ b/split_5s.sh @@ -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