Added standalone script
This commit is contained in:
parent
833b2835be
commit
dba258bfcb
38
README.md
38
README.md
@ -1,3 +1,41 @@
|
||||
# time-expanseR
|
||||
|
||||
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
43
expanseR.sh
Executable 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
|
@ -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
|
||||
|
66
split_5s.sh
66
split_5s.sh
@ -3,21 +3,18 @@
|
||||
##########################################################
|
||||
#
|
||||
# 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"
|
||||
}
|
||||
|
||||
if [ ! -d $outdir ];
|
||||
then
|
||||
mkdir $outdir
|
||||
fi
|
||||
|
||||
cd $indir
|
||||
|
||||
for item in `ls ./*.WAV`
|
||||
do
|
||||
function split {
|
||||
cd $indir
|
||||
for item in `ls ./*.WAV`
|
||||
do
|
||||
audio_dur=`sox --i -D $item`
|
||||
# Convert float to int
|
||||
audio_dur=${audio_dur%.*}
|
||||
@ -27,7 +24,50 @@ do
|
||||
for ss in `seq 0 5 $(( $audio_dur - 5 ))`
|
||||
do
|
||||
to=$(( $ss + 5 ))
|
||||
echo $ss $to
|
||||
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
|
||||
|
||||
split
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user