Learn R Programming

seewave (version 2.2.3)

sox: Calls SoX

Description

This function calls SoX, the Swiss Army knife of sound processing programs.

Usage

sox(command, exename = NULL, path2exe = NULL, option = NULL,
shQuote_type = NULL)

Arguments

command

the SoX command to invoke.

exename

a character string specifying the name of the SoX binary file. If NULL, the default name "sox" will be used for Linux OS.

path2exe

a character string giving the path to the SoX binary file

g

option

option to be passed to the SoX command

shQuote_type

type of shell quotes ("cmd" or "cmd2", for Windows OS; "sh" or "csh" Unix OS)

Author

Jerome Sueur, Stefanie LaZerte, Andre Mikulec

Details

See the documentation of SoX for proper use.

References

https://en.wikipedia.org/wiki/SoX

Examples

Run this code
if (FALSE) {
##########
## data ##
##########
## Generate a simple sound file at 440 Hz
s <- synth(cf=440, f=8000, d=1, fm=c(0,0,1000,0,0), output="Wave")
savewav(s, file="mysound.wav")
##############
## Linux OS ##
##############
## Play the file
sox("mysound.wav", exename="play")
## Slow down  the  audio  tempo  (but  not  its  pitch)
sox("mysound.wav myslowsound.wav tempo 0.5")
## Cut the file
sox("myslowsound.wav myslowcutsound.wav trim 0.25 0.75")
################
## Windows OS ##
################
## path with simple slash
path <- "C:/Program Files (x86)/sox-14-4-2"
## or path with double backslash
## path <- "C:\Program Files (x86)\sox-14-4-2"
sox("mysound.wav", path2exe=path, option="-t waveaudio")
## with the option directly passed to the command 
sox("mysound.wav -t waveaudio", path2exe=path)
## Slow down  the  audio  tempo  (but  not  its  pitch)
sox("mysound.wav myslowsound.wav tempo 0.5", path2exe=path)
## Cut the file
sox("myslowsound.wav myslowcutsound.wav trim 0.25 0.75", path2exe=path)
###########
## clean ##
###########
file.remove("mysound.wav", "myslowsound.wav", "myslowcutsound.wav")
}

Run the code above in your browser using DataLab