The retimer
package provides tools for retiming and
analysis of speech.
You can install the development version of retimer from GitHub:
::install_github("abeith/retimer") remotes
The WSOLA (Wave Similarity Overlap-Add) algorithm for performing retimings is implemented as a native R function.
For example, to create a random retiming of the included
mm1
Wave object:
library(retimer)
## Load example data
data(mm1)
## Find the length (in samples) of the object
<- length(mm1@left)
dur
## Set the number of anchors to use
<- 10
n
## Sample some random interval durations
<- runif(n)
x
## Make a list of input output anchors
<- list(anc_in = c(0, dur*seq_len(n)/n),
anchors anc_out = c(0, dur*cumsum(x)/sum(x)))
## Run the retiming
<- wsola(mm1@left, anchors)
sig
## Create a new Wave object with the retimed signal
<- tuneR::Wave(sig, samp.rate = mm1@samp.rate, bit = mm1@bit)
wav
## Listen to the retimed audio
::play(wav, 'play') tuneR
The praatRetime
function is used to perform a retiming
in Praat with the overlap-add
method. To use this function and other Praat functions in the
retimer
package, you must have Praat installed and
available in your PATH. Running the praatSys
function with
no arguments should output the Version number of your Praat
installation.
praatSys()
To create a similar retiming to the above wsola
example,
it is necessary to create a nested tibble that can be converted to a
TextGrid with the first tier indicating the existing timing and the
second tier indicating the desired timing.
library(retimer)
library(tidyverse)
## Load example data
data(mm1)
## Find the length (in seconds) of the object
<- length(mm1)/mm1@samp.rate
dur
## Set the number of anchors to use
<- runif(10)
x
## Define the ends of the intervals for the output tier
<- dur*cumsum(x)/sum(x)
t2_out ## Define the starts of the intervals for the output tier
<- c(0, t2_out[-length(t2_out)])
t1_out ## Define the ends of the intervals for the input tier
<- dur*seq_len(10)/10
t2_in ## Define the starts of the intervals for the input tier
<- c(0, t2_in[-length(t2_in)])
t1_in
## Create a TextGrid tibble
<- tibble(
tg name = rep(c("old", "new"), each = 10),
type = "interval",
t1 = c(t1_in, t1_out),
t2 = c(t2_in, t2_out),
label = rep(letters[1:10], times = 2)) |>
nest(data = c(t1, t2, label))
## Run the retiming
<- praatRetime(mm1, tg)
wav_retimed
## Listen to the retimed audio
::play(wav_retimed, 'play') tuneR