This vignette is considered deprecated! It's content has been moved to the the EMU-SDMS manual (+ expanded and updated). Specifially see the the R package wrassp as well as the wrassp implementation chapters.
This document is meant as an introduction to the
wrassp is a wrapper for R around Michel Scheffers's libassp
(Advanced Speech Signal Processor). The libassp library aims at
providing functionality for handling speech signal files in most
common audio formats and for performing analyses common in phonetic
science/speech science. This includes the calculation of formants,
fundamental frequency, root mean square, auto correlation, a variety
of spectral analyses, zero crossing rate, filtering etc. This wrapper
provides R with a large subset of libassp's signal processing
functions and provides them to the user in a (hopefully) user-friendly manner.
Let's get started by locating some example material distributed with the package.
# load the package library(wrassp) # get the path to the data that comes with the package wavPath = system.file('extdata', package='wrassp') # now list the .wav files so we have some audio files to play with wavFiles = list.files(wavPath, pattern=glob2rx('*.wav'), full.names=TRUE)
One of the aims of
wrassp is to provide mechanisms to handle
speech-related files such as sound files and parametric data
wrassp therefore comes with a class called
AsspDataObj which does just that.
# load an audio file, e.g. the first one in the list above au = read.AsspDataObj(wavFiles) # show class class(au) # print object description print(au)
au is an object of the class
AsspDataObj and, using
Here are some more ways of extracting attributes from the object, such as duration, sampling rate and the number of records:
# extract duration dur.AsspDataObj(au) # extract sampling rate rate.AsspDataObj(au) # extract number of records/samples numRecs.AsspDataObj(au) # extract additional attributes attributes(au)
An important property of
AsspDataObj is of course that it
contains data tracks, or at least one data track. As mentioned above,
the currently loaded object contains a single mono audio
track. Accessing the data is easy:
AsspDataObj stores data in
simple matrices, one matrix for each track. Broadly speaking,
AsspDataObj is nothing but a list of at least one matrix. All
of them have the same number of rows (number of records) but each can
have a different number of columns (number of fields). Each track has
a name and we can access the track using that name.
# extract track names tracks.AsspDataObj(au) # or an alternative way to extract track names names(au) # show head of samples head(au$audio) # and we can of course also plot these samples # (only plot every 10th element to accelerate plotting) plot(seq(0,numRecs.AsspDataObj(au) - 1, 10) / rate.AsspDataObj(au), au$audio[c(TRUE, rep(FALSE,9))], type='l', xlab='time (s)', ylab='Audio samples')
Now, purely to give us something unequal to the original
au object to write
to disc, let's manipulate the audio data by simply multiplying
all the sample values by a factor of
0.5. The resulting
AsspDataObj will then be saved to a temporary directory provided by
# manipulate the audio au$audio = au$audio * 0.5 # write file to tempdir dir = tempdir() writeres = write.AsspDataObj(au, file.path(dir, 'newau.wav'))
wrassp is of course capable of more than just the mere reading and writing
of specific signal file formats. We will now use
wrassp to calculate the formant values,
their corresponding bandwidths, the fundamental frequency contour and
the RMS energy contour of the audio file
# calculate formants and corresponding bandwidth values fmBwVals = forest(wavFiles, toFile=F) # due to toFile=F this returns an object of the type AsspDataObj and # prevents the result being saved to disc as an SSFF file class(fmBwVals) # extract track names # this time the object contains muliple tracks (formants + their bandwidths) tracks.AsspDataObj(fmBwVals) # with more than one field (in this case 250 F1/F2/F3/F4 values) dim(fmBwVals$fm) # plot the formant values matplot(seq(0,numRecs.AsspDataObj(fmBwVals) - 1) / rate.AsspDataObj(fmBwVals) + attr(fmBwVals, 'startTime'), fmBwVals$fm, type='l', xlab='time (s)', ylab='Formant frequency (Hz)')
# calculate the fundamental frequency contour f0vals = ksvF0(wavFiles, toFile=F) # plot the fundamental frequency contour plot(seq(0,numRecs.AsspDataObj(f0vals) - 1) / rate.AsspDataObj(f0vals) + attr(f0vals, 'startTime'), f0vals$F0, type='l', xlab='time (s)', ylab='F0 frequency (Hz)')
Seeing as one might want to reuse some of the computed signals at a later stage,
wrassp allows the user to write the result out to file by leaving the
toFile parameter set to
TRUE. This also allows users to process more than one file at
# calculate the RMS-energy contour for all wavFiles rmsana(wavFiles, outputDirectory = tempdir()) # list new files using wrasspOutputInfos$rmsana$ext (see below) rmsFilePaths = list.files(tempdir(), pattern = paste0('*.',wrasspOutputInfos$rmsana$ext), full.names = T) # read first rms file rmsvals = read.AsspDataObj(rmsFilePaths) # plot the RMS energy contour plot(seq(0,numRecs.AsspDataObj(rmsvals) - 1) / rate.AsspDataObj(rmsvals) + attr(rmsvals, 'startTime'), rmsvals$rms, type='l', xlab='time (s)', ylab='RMS energy (dB)')
wrasspOutputInfos stores meta information associated with the different signal
# show all function names names(wrasspOutputInfos)
This object can be useful to get additional information about a specific
wrassp function. It contains information about the default file extension (
the tracks produced (
$tracks) and the output file type (
# show output infos of function forest wrasspOutputInfos$forest
For a list of the available signal processing function provided by
open the package documentation:
# open wrassp package documentation ?wrassp
We hope this document gives you a rough idea of how to use the
wrassp package and what
it is capable of. For more information about the individual functions please consult the
respective R documentations (e.g.
To find questions that might have already been answered or if you have an issue or a bug to report please use our GitHub issue tracker.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.