Title: | Interface to Praat |
---|---|
Description: | Read, write and manipulate 'Praat' TextGrid, PitchTier, Pitch, IntensityTier, Formant, Sound, and Collection files <https://www.fon.hum.uva.nl/praat/>. |
Authors: | Tomas Boril [aut, cre] |
Maintainer: | Tomas Boril <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.3.2-1 |
Built: | 2025-03-06 04:49:13 UTC |
Source: | https://github.com/bbtomas/rpraat |
Renames the class(formant)["name"]
attribute and sets class(formant)["type"] <- "Formant 2"
(if it is not already set)
as.formant(formant, name = "")
as.formant(formant, name = "")
formant |
Formant 2 object |
name |
New name |
Formant 2 object
class(formant.sample()) class(as.formant(formant.sample(), name = "New Name"))
class(formant.sample()) class(as.formant(formant.sample(), name = "New Name"))
Renames the class(it)["name"]
attribute and sets class(it)["type"] <- "IntensityTier"
(if it is not already set)
as.it(it, name = "")
as.it(it, name = "")
it |
IntensityTier object |
name |
New name |
IntensityTier object
class(it.sample()) class(as.it(it.sample(), name = "New Name"))
class(it.sample()) class(as.it(it.sample(), name = "New Name"))
Renames the class(pitch)["name"]
attribute and sets class(pitch)["type"] <- "Pitch 1"
(if it is not already set)
as.pitch(pitch, name = "")
as.pitch(pitch, name = "")
pitch |
Pitch 1 object |
name |
New name |
Pitch 1 object
class(pitch.sample()) class(as.pitch(pitch.sample(), name = "New Name"))
class(pitch.sample()) class(as.pitch(pitch.sample(), name = "New Name"))
Renames the class(pt)["name"]
attribute and sets class(pt)["type"] <- "PitchTier"
(if it is not already set)
as.pt(pt, name = "")
as.pt(pt, name = "")
pt |
PitchTier object |
name |
New name |
PitchTier object
class(pt.sample()) class(as.pt(pt.sample(), name = "New Name"))
class(pt.sample()) class(as.pt(pt.sample(), name = "New Name"))
Renames the class(snd)["name"]
attribute and sets class(snd)["type"] <- "Sound"
(if it is not already set)
as.snd(snd, name = "")
as.snd(snd, name = "")
snd |
snd object |
name |
New name |
At least, $sig
and $fs
members must be present in snd
list.
If not present, it calculates $t
, $nChannels
, $nBits
(default: 16), $nSamples
, and $duration
members of snd
list
snd object
class(snd.sample()) class(as.snd(snd.sample(), name = "New Name"))
class(snd.sample()) class(as.snd(snd.sample(), name = "New Name"))
Renames the class(tg)["name"]
attribute and sets class(tg)["type"] <- "TextGrid" (if it is not already set)
as.tg(tg, name = "")
as.tg(tg, name = "")
tg |
TextGrid object |
name |
New name |
TextGrid object
class(tg.sample()) class(as.tg(tg.sample(), name = "New Name"))
class(tg.sample()) class(as.tg(tg.sample(), name = "New Name"))
Loads Collection from Praat in Text or Short text format. Collection may contain combination of TextGrids, PitchTiers, Pitch objects, Formant objects, and IntensityTiers.
col.read(fileName, encoding = "UTF-8")
col.read(fileName, encoding = "UTF-8")
fileName |
Input file name |
encoding |
File encoding (default: |
Collection object
tg.read
, pt.read
, pitch.read
, formant.read
, it.read
## Not run: coll <- col.read("coll_text.Collection") length(coll) # number of objects in collection class(coll[[1]])["type"] # 1st object type class(coll[[1]])["name"] # 1st object name it <- coll[[1]] # 1st object it.plot(it) class(coll[[2]])["type"] # 2nd object type class(coll[[2]])["name"] # 2nd object name tg <- coll[[2]] # 2nd object tg.plot(tg) length(tg) # number of tiers in TextGrid tg$word$label class(coll[[3]])["type"] # 3rd object type class(coll[[3]])["name"] # 3rd object type pitch <- coll[[3]] # 3rd object names(pitch) pitch$nx # number of frames pitch$t[4] # time instance of the 4th frame pitch$frame[[4]] # 4th frame: pitch candidates pitch$frame[[4]]$frequency[2] pitch$frame[[4]]$strength[2] class(coll[[4]])["type"] # 4th object type class(coll[[4]])["name"] # 4th object name pt <- coll[[4]] # 2nd object pt.plot(pt) ## End(Not run)
## Not run: coll <- col.read("coll_text.Collection") length(coll) # number of objects in collection class(coll[[1]])["type"] # 1st object type class(coll[[1]])["name"] # 1st object name it <- coll[[1]] # 1st object it.plot(it) class(coll[[2]])["type"] # 2nd object type class(coll[[2]])["name"] # 2nd object name tg <- coll[[2]] # 2nd object tg.plot(tg) length(tg) # number of tiers in TextGrid tg$word$label class(coll[[3]])["type"] # 3rd object type class(coll[[3]])["name"] # 3rd object type pitch <- coll[[3]] # 3rd object names(pitch) pitch$nx # number of frames pitch$t[4] # time instance of the 4th frame pitch$frame[[4]] # 4th frame: pitch candidates pitch$frame[[4]]$frequency[2] pitch$frame[[4]]$strength[2] class(coll[[4]])["type"] # 4th object type class(coll[[4]])["name"] # 4th object name pt <- coll[[4]] # 2nd object pt.plot(pt) ## End(Not run)
Saves Collection of objects to a file (in UTF-8 encoding). col
is list of objects, each item col[[i]]
must contain class(col[[i]])["type"]
("TextGrid", "PitchTier", "IntensityTier", "Pitch 1", or "Formant 2") and class(col[[i]])["name"]
(name of the object) parameters set.
These parameters can be created easily using "as.something()" functions: as.tg()
, as.pt()
, as.it()
, as.pitch()
, as.formant()
col.write(col, fileNameCollection, format = "short")
col.write(col, fileNameCollection, format = "short")
col |
Collection object = list of objects ( |
fileNameCollection |
file name to be created |
format |
Output file format ( |
Sound objects in col.read()
and col.write()
are not supported at this moment because they would occupy too much disc space in text format.
## Not run: col <- list(as.tg(tg.sample(), "My textgrid"), as.pt(pt.sample(), "My PitchTier 1"), as.pt(pt.Hz2ST(pt.sample()), "My PitchTier 2"), as.it(it.sample(), "My IntensityTier"), as.pitch(pitch.sample(), "My Pitch"), as.formant(formant.sample(), "My Formant")) col.write(col, "my_collection.Collection") ## End(Not run)
## Not run: col <- list(as.tg(tg.sample(), "My textgrid"), as.pt(pt.sample(), "My PitchTier 1"), as.pt(pt.Hz2ST(pt.sample()), "My PitchTier 2"), as.it(it.sample(), "My IntensityTier"), as.pitch(pitch.sample(), "My Pitch"), as.formant(formant.sample(), "My Formant")) col.write(col, "my_collection.Collection") ## End(Not run)
Detects unicode encoding of Praat text files
detectEncoding(fileName)
detectEncoding(fileName)
fileName |
Input file name |
detected encoding of the text input file
## Not run: detectEncoding("demo/H.TextGrid") detectEncoding("demo/H_UTF16.TextGrid") ## End(Not run)
## Not run: detectEncoding("demo/H.TextGrid") detectEncoding("demo/H_UTF16.TextGrid") ## End(Not run)
Cut the specified interval from the Formant object and preserve time
formant.cut(formant, tStart = -Inf, tEnd = Inf)
formant.cut(formant, tStart = -Inf, tEnd = Inf)
formant |
Formant object (either in Frame or Array format) |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
Formant object
formant.cut0
, tg.cut
, tg.cut0
, formant.read
, formant.plot
formant <- formant.sample() formant2 <- formant.cut(formant, tStart = 3) formant2_0 <- formant.cut0(formant, tStart = 3) formant3 <- formant.cut(formant, tStart = 2, tEnd = 3) formant3_0 <- formant.cut0(formant, tStart = 2, tEnd = 3) formant4 <- formant.cut(formant, tEnd = 1) formant4_0 <- formant.cut0(formant, tEnd = 1) formant5 <- formant.cut(formant, tStart = -1, tEnd = 1) formant5_0 <- formant.cut0(formant, tStart = -1, tEnd = 1) ## Not run: formant.plot(formant) formant.plot(formant2) formant.plot(formant2_0) formant.plot(formant3) formant.plot(formant3_0) formant.plot(formant4) formant.plot(formant4_0) formant.plot(formant5) formant.plot(formant5_0) ## End(Not run)
formant <- formant.sample() formant2 <- formant.cut(formant, tStart = 3) formant2_0 <- formant.cut0(formant, tStart = 3) formant3 <- formant.cut(formant, tStart = 2, tEnd = 3) formant3_0 <- formant.cut0(formant, tStart = 2, tEnd = 3) formant4 <- formant.cut(formant, tEnd = 1) formant4_0 <- formant.cut0(formant, tEnd = 1) formant5 <- formant.cut(formant, tStart = -1, tEnd = 1) formant5_0 <- formant.cut0(formant, tStart = -1, tEnd = 1) ## Not run: formant.plot(formant) formant.plot(formant2) formant.plot(formant2_0) formant.plot(formant3) formant.plot(formant3_0) formant.plot(formant4) formant.plot(formant4_0) formant.plot(formant5) formant.plot(formant5_0) ## End(Not run)
Cut the specified interval from the Formant object and shift time so that the new xmin
= 0
formant.cut0(formant, tStart = -Inf, tEnd = Inf)
formant.cut0(formant, tStart = -Inf, tEnd = Inf)
formant |
Formant object (either in Frame or Array format) |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
Formant object
formant.cut
, tg.cut
, tg.cut0
, formant.read
, formant.plot
formant <- formant.sample() formant2 <- formant.cut(formant, tStart = 3) formant2_0 <- formant.cut0(formant, tStart = 3) formant3 <- formant.cut(formant, tStart = 2, tEnd = 3) formant3_0 <- formant.cut0(formant, tStart = 2, tEnd = 3) formant4 <- formant.cut(formant, tEnd = 1) formant4_0 <- formant.cut0(formant, tEnd = 1) formant5 <- formant.cut(formant, tStart = -1, tEnd = 1) formant5_0 <- formant.cut0(formant, tStart = -1, tEnd = 1) ## Not run: formant.plot(formant) formant.plot(formant2) formant.plot(formant2_0) formant.plot(formant3) formant.plot(formant3_0) formant.plot(formant4) formant.plot(formant4_0) formant.plot(formant5) formant.plot(formant5_0) ## End(Not run)
formant <- formant.sample() formant2 <- formant.cut(formant, tStart = 3) formant2_0 <- formant.cut0(formant, tStart = 3) formant3 <- formant.cut(formant, tStart = 2, tEnd = 3) formant3_0 <- formant.cut0(formant, tStart = 2, tEnd = 3) formant4 <- formant.cut(formant, tEnd = 1) formant4_0 <- formant.cut0(formant, tEnd = 1) formant5 <- formant.cut(formant, tStart = -1, tEnd = 1) formant5_0 <- formant.cut0(formant, tStart = -1, tEnd = 1) ## Not run: formant.plot(formant) formant.plot(formant2) formant.plot(formant2_0) formant.plot(formant3) formant.plot(formant3_0) formant.plot(formant4) formant.plot(formant4_0) formant.plot(formant5) formant.plot(formant5_0) ## End(Not run)
Returns index of frame which is nearest the given time from right, i.e.
time
<= frameTime.
formant.getPointIndexHigherThanTime(formant, time)
formant.getPointIndexHigherThanTime(formant, time)
formant |
Formant object |
time |
time which is going to be found in frames |
integer
formant.getPointIndexNearestTime
, formant.getPointIndexLowerThanTime
formant <- formant.sample() formant.getPointIndexHigherThanTime(formant, 0.5)
formant <- formant.sample() formant.getPointIndexHigherThanTime(formant, 0.5)
Returns index of frame which is nearest the given time from left, i.e.
frameTime <= time
.
formant.getPointIndexLowerThanTime(formant, time)
formant.getPointIndexLowerThanTime(formant, time)
formant |
Formant object |
time |
time which is going to be found in frames |
integer
formant.getPointIndexNearestTime
, formant.getPointIndexHigherThanTime
formant <- formant.sample() formant.getPointIndexLowerThanTime(formant, 0.5)
formant <- formant.sample() formant.getPointIndexLowerThanTime(formant, 0.5)
Returns index of frame which is nearest the given time
(from both sides).
formant.getPointIndexNearestTime(formant, time)
formant.getPointIndexNearestTime(formant, time)
formant |
Formant object |
time |
time which is going to be found in frames |
integer
formant.getPointIndexLowerThanTime
, formant.getPointIndexHigherThanTime
formant <- formant.sample() formant.getPointIndexNearestTime(formant, 0.5)
formant <- formant.sample() formant.getPointIndexNearestTime(formant, 0.5)
Plots interactive Formant object using dygraphs
package.
formant.plot(formant, scaleIntensity = TRUE, drawBandwidth = TRUE, group = "")
formant.plot(formant, scaleIntensity = TRUE, drawBandwidth = TRUE, group = "")
formant |
Formant object |
scaleIntensity |
Point size scaled according to relative intensity |
drawBandwidth |
Draw formant bandwidth |
group |
[optional] character string, name of group for dygraphs synchronization |
formant.read
, formant.sample
, formant.toArray
, tg.plot
## Not run: formant <- formant.sample() formant.plot(formant, drawBandwidth = TRUE) ## End(Not run)
## Not run: formant <- formant.sample() formant.plot(formant, drawBandwidth = TRUE) ## End(Not run)
Reads Formant object from Praat. Supported formats: text file, short text file.
formant.read(fileNameFormant, encoding = "UTF-8")
formant.read(fileNameFormant, encoding = "UTF-8")
fileNameFormant |
file name of Formant object |
encoding |
File encoding (default: |
A Formant object represents formants as a function of time.
[ref: Praat help, https://www.fon.hum.uva.nl/praat/manual/Formant.html]
f$xmin
... start time (seconds)
f$xmax
... end time (seconds)
f$nx
... number of frames
f$dx
... time step = frame duration (seconds)
f$x1
... time associated with the first frame (seconds)
f$t
... vector of time instances associated with all frames
f$maxnFormants
... maximum number of formants in frame
f$frame[[1]]
to f$frame[[f$nx]]
... frames
f$frame[[1]]$intensity
... intensity of the frame
f$frame[[1]]$nFormants
... actual number of formants in this frame
f$frame[[1]]$frequency
... vector of formant frequencies (in Hz)
f$frame[[1]]$bandwidth
... vector of formant bandwidths (in Hz)
formant.write
, formant.plot
, formant.cut
, formant.getPointIndexNearestTime
, pitch.read
, pt.read
, tg.read
, it.read
, col.read
## Not run: f <- formant.read('demo/maminka.Formant') names(f) f$nx f$t[4] # time instance of the 4th frame f$frame[[4]] # 4th frame: formants f$frame[[4]]$frequency[2] f$frame[[4]]$bandwidth[2] ## End(Not run)
## Not run: f <- formant.read('demo/maminka.Formant') names(f) f$nx f$t[4] # time instance of the 4th frame f$frame[[4]] # 4th frame: formants f$frame[[4]]$frequency[2] f$frame[[4]]$bandwidth[2] ## End(Not run)
Returns sample Formant object.
formant.sample()
formant.sample()
Formant
tg.sample
, pt.sample
, it.sample
, pitch.sample
formant <- formant.sample()
formant <- formant.sample()
formant.toArray
formant.toArray(formant)
formant.toArray(formant)
formant |
Formant object |
Formant object with frames converted to frequency and bandwidth arrays and intensity vector
formantArray <- formant.toArray(formant.sample()) formantArray$t[1:10] formantArray$frequencyArray[, 1:10] formantArray$bandwidthArray[, 1:10] formantArray$intensityVector[1:10] ## Not run: plot(formantArray$t, formantArray$frequencyArray[1, ]) # draw 1st formant track ## End(Not run)
formantArray <- formant.toArray(formant.sample()) formantArray$t[1:10] formantArray$frequencyArray[, 1:10] formantArray$bandwidthArray[, 1:10] formantArray$intensityVector[1:10] ## Not run: plot(formantArray$t, formantArray$frequencyArray[1, ]) # draw 1st formant track ## End(Not run)
formant.toFrame
formant.toFrame(formantArray)
formant.toFrame(formantArray)
formantArray |
Formant object (array format) |
Formant object with frames
formant.toArray
, formant.read
, formant.plot
formantArray <- formant.toArray(formant.sample()) formant <- formant.toFrame(formantArray)
formantArray <- formant.toArray(formant.sample()) formant <- formant.toFrame(formantArray)
Saves Formant to the file.
formant.write(formant, fileNameFormant, format = "short")
formant.write(formant, fileNameFormant, format = "short")
formant |
Formant object |
fileNameFormant |
Output file name |
format |
Output file format ( |
## Not run: formant <- formant.sample() formant.write(formant, "demo_output.Formant") ## End(Not run)
## Not run: formant <- formant.sample() formant.write(formant, "demo_output.Formant") ## End(Not run)
Inverse Fast Fourier Transform (discrete FT), Matlab-like behavior.
ifft(sig)
ifft(sig)
sig |
input vector |
This really is the inverse of the fft function, so ifft(fft(x)) == x
.
output vector of the same length as the input vector
ifft(fft(1:5))
ifft(fft(1:5))
Returns TRUE
/ FALSE
whether it is exactly 1 integer number (in fact, the class can be numeric but the number must be integer), non-missing
isInt(num)
isInt(num)
num |
variable to be tested |
TRUE
/ FALSE
isInt(2) isInt(2L) isInt(-2) isInt(-2L) isInt(2.1) isInt(-2.1) isInt(1:5) isInt(NA_integer_) isInt(integer(0))
isInt(2) isInt(2L) isInt(-2) isInt(-2L) isInt(2.1) isInt(-2.1) isInt(1:5) isInt(NA_integer_) isInt(integer(0))
Returns TRUE
/ FALSE
whether it is exactly 1 logical value, non-missing
isLogical(logical)
isLogical(logical)
logical |
variable to be tested |
TRUE
/ FALSE
isLogical(TRUE) isLogical(FALSE) isLogical(1) isLogical(0) isLogical(2) isLogical(NA) isLogical(NaN) isLogical(logical(0))
isLogical(TRUE) isLogical(FALSE) isLogical(1) isLogical(0) isLogical(2) isLogical(NA) isLogical(NaN) isLogical(logical(0))
Returns TRUE
/ FALSE
whether it is exactly 1 number (numeric or integer vector of length 1, non-missing)
isNum(num)
isNum(num)
num |
variable to be tested |
TRUE
/ FALSE
isNum(2) isNum(2L) isNum(-2) isNum(-2L) isNum(2.1) isNum(-2.1) isNum(1:5) isNum(NA_real_) isNum(numeric(0))
isNum(2) isNum(2L) isNum(-2) isNum(-2L) isNum(2.1) isNum(-2.1) isNum(1:5) isNum(NA_real_) isNum(numeric(0))
Returns TRUE
/ FALSE
whether it is exactly 1 character string (character vector of length 1, non-missing)
isString(string)
isString(string)
string |
variable to be tested |
TRUE
/ FALSE
isString("hello") isString(2) isString(c("hello", "world")) isString(NA_character_)
isString("hello") isString(2) isString(c("hello", "world")) isString(NA_character_)
Cut the specified interval from the IntensityTier and preserve time
it.cut(it, tStart = -Inf, tEnd = Inf)
it.cut(it, tStart = -Inf, tEnd = Inf)
it |
IntensityTier object |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
IntensityTier object
it.cut0
, it.read
, it.plot
, it.interpolate
, it.legendre
, it.legendreSynth
, it.legendreDemo
it <- it.sample() it2 <- it.cut(it, tStart = 0.3) it2_0 <- it.cut0(it, tStart = 0.3) it3 <- it.cut(it, tStart = 0.2, tEnd = 0.3) it3_0 <- it.cut0(it, tStart = 0.2, tEnd = 0.3) it4 <- it.cut(it, tEnd = 0.3) it4_0 <- it.cut0(it, tEnd = 0.3) it5 <- it.cut(it, tStart = -1, tEnd = 1) it5_0 <- it.cut0(it, tStart = -1, tEnd = 1) ## Not run: it.plot(it) it.plot(it2) it.plot(it2_0) it.plot(it3) it.plot(it3_0) it.plot(it4) it.plot(it4_0) it.plot(it5) it.plot(it5_0) ## End(Not run)
it <- it.sample() it2 <- it.cut(it, tStart = 0.3) it2_0 <- it.cut0(it, tStart = 0.3) it3 <- it.cut(it, tStart = 0.2, tEnd = 0.3) it3_0 <- it.cut0(it, tStart = 0.2, tEnd = 0.3) it4 <- it.cut(it, tEnd = 0.3) it4_0 <- it.cut0(it, tEnd = 0.3) it5 <- it.cut(it, tStart = -1, tEnd = 1) it5_0 <- it.cut0(it, tStart = -1, tEnd = 1) ## Not run: it.plot(it) it.plot(it2) it.plot(it2_0) it.plot(it3) it.plot(it3_0) it.plot(it4) it.plot(it4_0) it.plot(it5) it.plot(it5_0) ## End(Not run)
Cut the specified interval from the IntensityTier and shift time so that the new tmin
= 0
it.cut0(it, tStart = -Inf, tEnd = Inf)
it.cut0(it, tStart = -Inf, tEnd = Inf)
it |
IntensityTier object |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
IntensityTier object
it.cut
, it.read
, it.plot
, it.interpolate
, it.legendre
, it.legendreSynth
, it.legendreDemo
it <- it.sample() it2 <- it.cut(it, tStart = 0.3) it2_0 <- it.cut0(it, tStart = 0.3) it3 <- it.cut(it, tStart = 0.2, tEnd = 0.3) it3_0 <- it.cut0(it, tStart = 0.2, tEnd = 0.3) it4 <- it.cut(it, tEnd = 0.3) it4_0 <- it.cut0(it, tEnd = 0.3) it5 <- it.cut(it, tStart = -1, tEnd = 1) it5_0 <- it.cut0(it, tStart = -1, tEnd = 1) ## Not run: it.plot(it) it.plot(it2) it.plot(it2_0) it.plot(it3) it.plot(it3_0) it.plot(it4) it.plot(it4_0) it.plot(it5) it.plot(it5_0) ## End(Not run)
it <- it.sample() it2 <- it.cut(it, tStart = 0.3) it2_0 <- it.cut0(it, tStart = 0.3) it3 <- it.cut(it, tStart = 0.2, tEnd = 0.3) it3_0 <- it.cut0(it, tStart = 0.2, tEnd = 0.3) it4 <- it.cut(it, tEnd = 0.3) it4_0 <- it.cut0(it, tEnd = 0.3) it5 <- it.cut(it, tStart = -1, tEnd = 1) it5_0 <- it.cut0(it, tStart = -1, tEnd = 1) ## Not run: it.plot(it) it.plot(it2) it.plot(it2_0) it.plot(it3) it.plot(it3_0) it.plot(it4) it.plot(it4_0) it.plot(it5) it.plot(it5_0) ## End(Not run)
Returns index of point which is nearest the given time from right, i.e.
time
<= pointTime.
it.getPointIndexHigherThanTime(it, time)
it.getPointIndexHigherThanTime(it, time)
it |
IntensityTier object |
time |
time which is going to be found in points |
integer
it.getPointIndexNearestTime
, it.getPointIndexLowerThanTime
it <- it.sample() it.getPointIndexHigherThanTime(it, 0.5)
it <- it.sample() it.getPointIndexHigherThanTime(it, 0.5)
Returns index of point which is nearest the given time from left, i.e.
pointTime <= time
.
it.getPointIndexLowerThanTime(it, time)
it.getPointIndexLowerThanTime(it, time)
it |
IntensityTier object |
time |
time which is going to be found in points |
integer
it.getPointIndexNearestTime
, it.getPointIndexHigherThanTime
it <- it.sample() it.getPointIndexLowerThanTime(it, 0.5)
it <- it.sample() it.getPointIndexLowerThanTime(it, 0.5)
Returns index of point which is nearest the given time
(from both sides).
it.getPointIndexNearestTime(it, time)
it.getPointIndexNearestTime(it, time)
it |
IntensityTier object |
time |
time which is going to be found in points |
integer
it.getPointIndexLowerThanTime
, it.getPointIndexHigherThanTime
it <- it.sample() it.getPointIndexNearestTime(it, 0.5)
it <- it.sample() it.getPointIndexNearestTime(it, 0.5)
Interpolates IntensityTier contour in given time instances.
it.interpolate(it, t)
it.interpolate(it, t)
it |
IntensityTier object |
t |
vector of time instances of interest |
a) If t < min(it$t
) (or t > max(it$t)
), returns the first (or the last) value of it$i
.
b) If t
is existing point in it$t
, returns the respective it$f
.
c) If t
is between two existing points, returns linear interpolation of these two points.
IntensityTier object
it.getPointIndexNearestTime
, it.read
, it.write
, it.plot
, it.cut
, it.cut0
, it.legendre
it <- it.sample() it2 <- it.interpolate(it, seq(it$t[1], it$t[length(it$t)], by = 0.001)) ## Not run: it.plot(it) it.plot(it2) ## End(Not run)
it <- it.sample() it2 <- it.interpolate(it, seq(it$t[1], it$t[length(it$t)], by = 0.001)) ## Not run: it.plot(it) it.plot(it2) ## End(Not run)
Interpolate the IntensityTier in npoints
equidistant points and approximate it by Legendre polynomials
it.legendre(it, npoints = 1000, npolynomials = 4)
it.legendre(it, npoints = 1000, npolynomials = 4)
it |
IntensityTier object |
npoints |
Number of points of IntensityTier interpolation |
npolynomials |
Number of polynomials to be used for Legendre modelling |
Vector of Legendre polynomials coefficients
it.legendreSynth
, it.legendreDemo
, it.cut
, it.cut0
, it.read
, it.plot
, it.interpolate
it <- it.sample() it <- it.cut(it, tStart = 0.2, tEnd = 0.4) # cut IntensityTier and preserve time c <- it.legendre(it) print(c) leg <- it.legendreSynth(c) itLeg <- it itLeg$t <- seq(itLeg$tmin, itLeg$tmax, length.out = length(leg)) itLeg$i <- leg ## Not run: plot(it$t, it$i, xlab = "Time (sec)", ylab = "Intensity (dB)") lines(itLeg$t, itLeg$i, col = "blue") ## End(Not run)
it <- it.sample() it <- it.cut(it, tStart = 0.2, tEnd = 0.4) # cut IntensityTier and preserve time c <- it.legendre(it) print(c) leg <- it.legendreSynth(c) itLeg <- it itLeg$t <- seq(itLeg$tmin, itLeg$tmax, length.out = length(leg)) itLeg$i <- leg ## Not run: plot(it$t, it$i, xlab = "Time (sec)", ylab = "Intensity (dB)") lines(itLeg$t, itLeg$i, col = "blue") ## End(Not run)
Plots first four Legendre polynomials
it.legendreDemo()
it.legendreDemo()
it.legendre
, it.legendreSynth
, it.read
, it.plot
, it.interpolate
## Not run: it.legendreDemo() ## End(Not run)
## Not run: it.legendreDemo() ## End(Not run)
Synthetize the contour from vector of Legendre polynomials c
in npoints
equidistant points
it.legendreSynth(c, npoints = 1000)
it.legendreSynth(c, npoints = 1000)
c |
Vector of Legendre polynomials coefficients |
npoints |
Number of points of IntensityTier interpolation |
Vector of values of synthetized contour
it.legendre
, it.legendreDemo
, it.read
, it.plot
, it.interpolate
it <- it.sample() it <- it.cut(it, tStart = 0.2, tEnd = 0.4) # cut IntensityTier and preserve time c <- it.legendre(it) print(c) leg <- it.legendreSynth(c) itLeg <- it itLeg$t <- seq(itLeg$tmin, itLeg$tmax, length.out = length(leg)) itLeg$i <- leg ## Not run: plot(it$t, it$i, xlab = "Time (sec)", ylab = "Intensity (dB)") lines(itLeg$t, itLeg$i, col = "blue") ## End(Not run)
it <- it.sample() it <- it.cut(it, tStart = 0.2, tEnd = 0.4) # cut IntensityTier and preserve time c <- it.legendre(it) print(c) leg <- it.legendreSynth(c) itLeg <- it itLeg$t <- seq(itLeg$tmin, itLeg$tmax, length.out = length(leg)) itLeg$i <- leg ## Not run: plot(it$t, it$i, xlab = "Time (sec)", ylab = "Intensity (dB)") lines(itLeg$t, itLeg$i, col = "blue") ## End(Not run)
Plots interactive IntensityTier using dygraphs
package.
it.plot(it, group = "", snd = NULL)
it.plot(it, group = "", snd = NULL)
it |
IntensityTier object |
group |
[optional] character string, name of group for dygraphs synchronization |
snd |
[optional] Sound object |
it.read
, tg.plot
, it.cut
, it.cut0
, it.interpolate
, it.write
## Not run: it <- it.sample() it.plot(it) ## End(Not run)
## Not run: it <- it.sample() it.plot(it) ## End(Not run)
Reads IntensityTier from Praat. Supported formats: text file, short text file.
it.read(fileNameIntensityTier, encoding = "UTF-8")
it.read(fileNameIntensityTier, encoding = "UTF-8")
fileNameIntensityTier |
file name of IntensityTier |
encoding |
File encoding (default: |
IntensityTier object
it.write
, it.plot
, it.cut
, it.cut0
, it.interpolate
, tg.read
, pt.read
, pitch.read
, formant.read
, col.read
## Not run: it <- it.read("demo/maminka.IntensityTier") it.plot(it) ## End(Not run)
## Not run: it <- it.read("demo/maminka.IntensityTier") it.plot(it) ## End(Not run)
Saves IntensityTier to file (in UTF-8 encoding).
it is list with at least $t
and $i
vectors (of the same length).
If there are no $tmin
and $tmax
values, there are
set as min and max of $t
vector.
it.write(it, fileNameIntensityTier, format = "short")
it.write(it, fileNameIntensityTier, format = "short")
it |
IntensityTier object |
fileNameIntensityTier |
file name to be created |
format |
Output file format ( |
it.read
, tg.write
, it.interpolate
## Not run: it <- it.sample() it.plot(pt) it.write(it, "demo/intensity.IntensityTier") ## End(Not run)
## Not run: it <- it.sample() it.plot(pt) it.write(it, "demo/intensity.IntensityTier") ## End(Not run)
Cut the specified interval from the Pitch object and preserve time
pitch.cut(pitch, tStart = -Inf, tEnd = Inf)
pitch.cut(pitch, tStart = -Inf, tEnd = Inf)
pitch |
Pitch object (either in Frame or Array format) |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
Pitch object
pitch.cut0
, tg.cut
, tg.cut0
, pitch.read
, pitch.plot
pitch <- pitch.sample() pitch2 <- pitch.cut(pitch, tStart = 3) pitch2_0 <- pitch.cut0(pitch, tStart = 3) pitch3 <- pitch.cut(pitch, tStart = 2, tEnd = 3) pitch3_0 <- pitch.cut0(pitch, tStart = 2, tEnd = 3) pitch4 <- pitch.cut(pitch, tEnd = 1) pitch4_0 <- pitch.cut0(pitch, tEnd = 1) pitch5 <- pitch.cut(pitch, tStart = -1, tEnd = 1) pitch5_0 <- pitch.cut0(pitch, tStart = -1, tEnd = 1) ## Not run: pitch.plot(pitch) pitch.plot(pitch2) pitch.plot(pitch2_0) pitch.plot(pitch3) pitch.plot(pitch3_0) pitch.plot(pitch4) pitch.plot(pitch4_0) pitch.plot(pitch5) pitch.plot(pitch5_0) ## End(Not run)
pitch <- pitch.sample() pitch2 <- pitch.cut(pitch, tStart = 3) pitch2_0 <- pitch.cut0(pitch, tStart = 3) pitch3 <- pitch.cut(pitch, tStart = 2, tEnd = 3) pitch3_0 <- pitch.cut0(pitch, tStart = 2, tEnd = 3) pitch4 <- pitch.cut(pitch, tEnd = 1) pitch4_0 <- pitch.cut0(pitch, tEnd = 1) pitch5 <- pitch.cut(pitch, tStart = -1, tEnd = 1) pitch5_0 <- pitch.cut0(pitch, tStart = -1, tEnd = 1) ## Not run: pitch.plot(pitch) pitch.plot(pitch2) pitch.plot(pitch2_0) pitch.plot(pitch3) pitch.plot(pitch3_0) pitch.plot(pitch4) pitch.plot(pitch4_0) pitch.plot(pitch5) pitch.plot(pitch5_0) ## End(Not run)
Cut the specified interval from the Pitch object and shift time so that the new xmin
= 0
pitch.cut0(pitch, tStart = -Inf, tEnd = Inf)
pitch.cut0(pitch, tStart = -Inf, tEnd = Inf)
pitch |
Pitch object (either in Frame or Array format) |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
Pitch object
pitch.cut
, tg.cut
, tg.cut0
, pitch.read
, pitch.plot
pitch <- pitch.sample() pitch2 <- pitch.cut(pitch, tStart = 3) pitch2_0 <- pitch.cut0(pitch, tStart = 3) pitch3 <- pitch.cut(pitch, tStart = 2, tEnd = 3) pitch3_0 <- pitch.cut0(pitch, tStart = 2, tEnd = 3) pitch4 <- pitch.cut(pitch, tEnd = 1) pitch4_0 <- pitch.cut0(pitch, tEnd = 1) pitch5 <- pitch.cut(pitch, tStart = -1, tEnd = 1) pitch5_0 <- pitch.cut0(pitch, tStart = -1, tEnd = 1) ## Not run: pitch.plot(pitch) pitch.plot(pitch2) pitch.plot(pitch2_0) pitch.plot(pitch3) pitch.plot(pitch3_0) pitch.plot(pitch4) pitch.plot(pitch4_0) pitch.plot(pitch5) pitch.plot(pitch5_0) ## End(Not run)
pitch <- pitch.sample() pitch2 <- pitch.cut(pitch, tStart = 3) pitch2_0 <- pitch.cut0(pitch, tStart = 3) pitch3 <- pitch.cut(pitch, tStart = 2, tEnd = 3) pitch3_0 <- pitch.cut0(pitch, tStart = 2, tEnd = 3) pitch4 <- pitch.cut(pitch, tEnd = 1) pitch4_0 <- pitch.cut0(pitch, tEnd = 1) pitch5 <- pitch.cut(pitch, tStart = -1, tEnd = 1) pitch5_0 <- pitch.cut0(pitch, tStart = -1, tEnd = 1) ## Not run: pitch.plot(pitch) pitch.plot(pitch2) pitch.plot(pitch2_0) pitch.plot(pitch3) pitch.plot(pitch3_0) pitch.plot(pitch4) pitch.plot(pitch4_0) pitch.plot(pitch5) pitch.plot(pitch5_0) ## End(Not run)
Returns index of frame which is nearest the given time from right, i.e.
time
<= frameTime.
pitch.getPointIndexHigherThanTime(pitch, time)
pitch.getPointIndexHigherThanTime(pitch, time)
pitch |
Pitch object |
time |
time which is going to be found in frames |
integer
pitch.getPointIndexNearestTime
, pitch.getPointIndexLowerThanTime
pitch <- pitch.sample() pitch.getPointIndexHigherThanTime(pitch, 0.5)
pitch <- pitch.sample() pitch.getPointIndexHigherThanTime(pitch, 0.5)
Returns index of frame which is nearest the given time from left, i.e.
frameTime <= time
.
pitch.getPointIndexLowerThanTime(pitch, time)
pitch.getPointIndexLowerThanTime(pitch, time)
pitch |
Pitch object |
time |
time which is going to be found in frames |
integer
pitch.getPointIndexNearestTime
, pitch.getPointIndexHigherThanTime
pitch <- pitch.sample() pitch.getPointIndexLowerThanTime(pitch, 0.5)
pitch <- pitch.sample() pitch.getPointIndexLowerThanTime(pitch, 0.5)
Returns index of frame which is nearest the given time
(from both sides).
pitch.getPointIndexNearestTime(pitch, time)
pitch.getPointIndexNearestTime(pitch, time)
pitch |
Pitch object |
time |
time which is going to be found in frames |
integer
pitch.getPointIndexLowerThanTime
, pitch.getPointIndexHigherThanTime
pitch <- pitch.sample() pitch.getPointIndexNearestTime(pitch, 0.5)
pitch <- pitch.sample() pitch.getPointIndexNearestTime(pitch, 0.5)
Plots interactive Pitch object using dygraphs
package.
pitch.plot( pitch, scaleIntensity = TRUE, showStrength = FALSE, group = "", pt = NULL )
pitch.plot( pitch, scaleIntensity = TRUE, showStrength = FALSE, group = "", pt = NULL )
pitch |
Pitch object |
scaleIntensity |
Point size scaled according to relative intensity |
showStrength |
Show strength annotation |
group |
[optional] character string, name of group for dygraphs synchronization |
pt |
[optional] PitchTier object |
pitch.read
, pitch.sample
, pitch.toArray
, tg.plot
, pt.plot
, formant.plot
## Not run: pitch <- pitch.sample() pitch.plot(pitch, scaleIntensity = TRUE, showStrength = TRUE) pitch.plot(pitch, scaleIntensity = TRUE, showStrength = TRUE, pt = pt.sample()) ## End(Not run)
## Not run: pitch <- pitch.sample() pitch.plot(pitch, scaleIntensity = TRUE, showStrength = TRUE) pitch.plot(pitch, scaleIntensity = TRUE, showStrength = TRUE, pt = pt.sample()) ## End(Not run)
Reads Pitch object from Praat. Supported formats: text file, short text file.
pitch.read(fileNamePitch, encoding = "UTF-8")
pitch.read(fileNamePitch, encoding = "UTF-8")
fileNamePitch |
file name of Pitch object |
encoding |
File encoding (default: |
A Pitch object represents periodicity candidates as a function of time.
[ref: Praat help, https://www.fon.hum.uva.nl/praat/manual/Pitch.html]
p$xmin
... start time (seconds)
p$xmax
... end time (seconds)
p$nx
... number of frames
p$dx
... time step = frame duration (seconds)
p$x1
... time associated with the first frame (seconds)
p$t
... vector of time instances associated with all frames
p$ceiling
... a frequency above which a candidate is considered voiceless (Hz)
p$maxnCandidates
... maximum number of candidates in frame
p$frame[[1]]
to p$frame[[p$nx]]
... frames
p$frame[[1]]$intensity
... intensity of the frame
p$frame[[1]]$nCandidates
... actual number of candidates in this frame
p$frame[[1]]$frequency
... vector of candidates' frequency (in Hz)
(for a voiced candidate), or 0
(for an unvoiced candidate)
p$frame[[1]]$strength
... vector of degrees of periodicity of candidates (between 0
and 1
)
pitch.write
, pitch.plot
, pitch.cut
, pitch.getPointIndexNearestTime
, pt.read
, tg.read
, it.read
, col.read
## Not run: p <- pitch.read('demo/sound.Pitch') names(p) p$nx p$t[4] # time instance of the 4th frame p$frame[[4]] # 4th frame: pitch candidates p$frame[[4]]$frequency[2] p$frame[[4]]$strength[2] ## End(Not run)
## Not run: p <- pitch.read('demo/sound.Pitch') names(p) p$nx p$t[4] # time instance of the 4th frame p$frame[[4]] # 4th frame: pitch candidates p$frame[[4]]$frequency[2] p$frame[[4]]$strength[2] ## End(Not run)
Returns sample Pitch object.
pitch.sample()
pitch.sample()
Pitch
tg.sample
, pt.sample
, it.sample
, formant.sample
pitch <- pitch.sample()
pitch <- pitch.sample()
pitch.toArray
pitch.toArray(pitch)
pitch.toArray(pitch)
pitch |
Pitch object (frame format) |
Pitch object with frames converted to frequency and strength arrays and intensity vector
pitch.toFrame
, pitch.read
, pitch.plot
pitchArray <- pitch.toArray(pitch.sample()) pitchArray$t[1:10] pitchArray$frequencyArray[, 1:10] pitchArray$bandwidthArray[, 1:10] pitchArray$intensityVector[1:10]
pitchArray <- pitch.toArray(pitch.sample()) pitchArray$t[1:10] pitchArray$frequencyArray[, 1:10] pitchArray$bandwidthArray[, 1:10] pitchArray$intensityVector[1:10]
pitch.toFrame
pitch.toFrame(pitchArray)
pitch.toFrame(pitchArray)
pitchArray |
Pitch object (array format) |
Pitch object with frames
pitch.toArray
, pitch.read
, pitch.plot
pitchArray <- pitch.toArray(pitch.sample()) pitch <- pitch.toFrame(pitchArray)
pitchArray <- pitch.toArray(pitch.sample()) pitch <- pitch.toFrame(pitchArray)
Saves Pitch to the file.
pitch.write(pitch, fileNamePitch, format = "short")
pitch.write(pitch, fileNamePitch, format = "short")
pitch |
Pitch object |
fileNamePitch |
Output file name |
format |
Output file format ( |
## Not run: pitch <- pitch.sample() pitch.write(pitch, "demo_output.Pitch") ## End(Not run)
## Not run: pitch <- pitch.sample() pitch.write(pitch, "demo_output.Pitch") ## End(Not run)
Cut the specified interval from the PitchTier and preserve time
pt.cut(pt, tStart = -Inf, tEnd = Inf)
pt.cut(pt, tStart = -Inf, tEnd = Inf)
pt |
PitchTier object |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
PitchTier object
pt.cut0
, tg.cut
, tg.cut0
, pt.read
, pt.plot
, pt.Hz2ST
, pt.interpolate
, pt.legendre
, pt.legendreSynth
, pt.legendreDemo
pt <- pt.sample() pt2 <- pt.cut(pt, tStart = 3) pt2_0 <- pt.cut0(pt, tStart = 3) pt3 <- pt.cut(pt, tStart = 2, tEnd = 3) pt3_0 <- pt.cut0(pt, tStart = 2, tEnd = 3) pt4 <- pt.cut(pt, tEnd = 1) pt4_0 <- pt.cut0(pt, tEnd = 1) pt5 <- pt.cut(pt, tStart = -1, tEnd = 1) pt5_0 <- pt.cut0(pt, tStart = -1, tEnd = 1) ## Not run: pt.plot(pt) pt.plot(pt2) pt.plot(pt2_0) pt.plot(pt3) pt.plot(pt3_0) pt.plot(pt4) pt.plot(pt4_0) pt.plot(pt5) pt.plot(pt5_0) ## End(Not run)
pt <- pt.sample() pt2 <- pt.cut(pt, tStart = 3) pt2_0 <- pt.cut0(pt, tStart = 3) pt3 <- pt.cut(pt, tStart = 2, tEnd = 3) pt3_0 <- pt.cut0(pt, tStart = 2, tEnd = 3) pt4 <- pt.cut(pt, tEnd = 1) pt4_0 <- pt.cut0(pt, tEnd = 1) pt5 <- pt.cut(pt, tStart = -1, tEnd = 1) pt5_0 <- pt.cut0(pt, tStart = -1, tEnd = 1) ## Not run: pt.plot(pt) pt.plot(pt2) pt.plot(pt2_0) pt.plot(pt3) pt.plot(pt3_0) pt.plot(pt4) pt.plot(pt4_0) pt.plot(pt5) pt.plot(pt5_0) ## End(Not run)
Cut the specified interval from the PitchTier and shift time so that the new tmin
= 0
pt.cut0(pt, tStart = -Inf, tEnd = Inf)
pt.cut0(pt, tStart = -Inf, tEnd = Inf)
pt |
PitchTier object |
tStart |
beginning time of interval to be cut (default |
tEnd |
final time of interval to be cut (default |
PitchTier object
pt.cut
, pt.read
, pt.plot
, pt.Hz2ST
, pt.interpolate
, pt.legendre
, pt.legendreSynth
, pt.legendreDemo
pt <- pt.sample() pt2 <- pt.cut(pt, tStart = 3) pt2_0 <- pt.cut0(pt, tStart = 3) pt3 <- pt.cut(pt, tStart = 2, tEnd = 3) pt3_0 <- pt.cut0(pt, tStart = 2, tEnd = 3) pt4 <- pt.cut(pt, tEnd = 1) pt4_0 <- pt.cut0(pt, tEnd = 1) pt5 <- pt.cut(pt, tStart = -1, tEnd = 1) pt5_0 <- pt.cut0(pt, tStart = -1, tEnd = 1) ## Not run: pt.plot(pt) pt.plot(pt2) pt.plot(pt2_0) pt.plot(pt3) pt.plot(pt3_0) pt.plot(pt4) pt.plot(pt4_0) pt.plot(pt5) pt.plot(pt5_0) ## End(Not run)
pt <- pt.sample() pt2 <- pt.cut(pt, tStart = 3) pt2_0 <- pt.cut0(pt, tStart = 3) pt3 <- pt.cut(pt, tStart = 2, tEnd = 3) pt3_0 <- pt.cut0(pt, tStart = 2, tEnd = 3) pt4 <- pt.cut(pt, tEnd = 1) pt4_0 <- pt.cut0(pt, tEnd = 1) pt5 <- pt.cut(pt, tStart = -1, tEnd = 1) pt5_0 <- pt.cut0(pt, tStart = -1, tEnd = 1) ## Not run: pt.plot(pt) pt.plot(pt2) pt.plot(pt2_0) pt.plot(pt3) pt.plot(pt3_0) pt.plot(pt4) pt.plot(pt4_0) pt.plot(pt5) pt.plot(pt5_0) ## End(Not run)
Returns index of point which is nearest the given time from right, i.e.
time
<= pointTime.
pt.getPointIndexHigherThanTime(pt, time)
pt.getPointIndexHigherThanTime(pt, time)
pt |
PitchTier object |
time |
time which is going to be found in points |
integer
pt.getPointIndexNearestTime
, pt.getPointIndexLowerThanTime
pt <- pt.sample() pt.getPointIndexHigherThanTime(pt, 0.5)
pt <- pt.sample() pt.getPointIndexHigherThanTime(pt, 0.5)
Returns index of point which is nearest the given time from left, i.e.
pointTime <= time
.
pt.getPointIndexLowerThanTime(pt, time)
pt.getPointIndexLowerThanTime(pt, time)
pt |
PitchTier object |
time |
time which is going to be found in points |
integer
pt.getPointIndexNearestTime
, pt.getPointIndexHigherThanTime
pt <- pt.sample() pt.getPointIndexLowerThanTime(pt, 0.5)
pt <- pt.sample() pt.getPointIndexLowerThanTime(pt, 0.5)
Returns index of point which is nearest the given time
(from both sides).
pt.getPointIndexNearestTime(pt, time)
pt.getPointIndexNearestTime(pt, time)
pt |
PitchTier object |
time |
time which is going to be found in points |
integer
pt.getPointIndexLowerThanTime
, pt.getPointIndexHigherThanTime
pt <- pt.sample() pt.getPointIndexNearestTime(pt, 0.5)
pt <- pt.sample() pt.getPointIndexNearestTime(pt, 0.5)
Converts Hz to Semitones with given reference (default 0 ST = 100 Hz).
pt.Hz2ST(pt, ref = 100)
pt.Hz2ST(pt, ref = 100)
pt |
PitchTier object |
ref |
reference value (in Hz) for 0 ST. Default: 100 Hz. |
PitchTier object
pt.read
, pt.write
, pt.plot
, pt.interpolate
, pt.cut
, pt.cut0
pt <- pt.sample() pt2 <- pt.Hz2ST(pt, ref = 200) ## Not run: pt.plot(pt) %>% dygraphs::dyAxis("y", label = "Frequency (Hz)") pt.plot(pt2) %>% dygraphs::dyAxis("y", label = "Frequency (ST re 200 Hz)") ## End(Not run)
pt <- pt.sample() pt2 <- pt.Hz2ST(pt, ref = 200) ## Not run: pt.plot(pt) %>% dygraphs::dyAxis("y", label = "Frequency (Hz)") pt.plot(pt2) %>% dygraphs::dyAxis("y", label = "Frequency (ST re 200 Hz)") ## End(Not run)
Interpolates PitchTier contour in given time instances.
pt.interpolate(pt, t)
pt.interpolate(pt, t)
pt |
PitchTier object |
t |
vector of time instances of interest |
a) If t < min(pt$t)
(or t > max(pt$t)
), returns the first (or the last) value of pt$f
.
b) If t
is existing point in pt$t
, returns the respective pt$f
.
c) If t
is between two existing points, returns linear interpolation of these two points.
PitchTier object
pt.getPointIndexNearestTime
, pt.read
, pt.write
, pt.plot
, pt.Hz2ST
, pt.cut
, pt.cut0
, pt.legendre
pt <- pt.sample() pt <- pt.Hz2ST(pt, ref = 100) # conversion of Hz to Semitones, reference 0 ST = 100 Hz. pt2 <- pt.interpolate(pt, seq(pt$t[1], pt$t[length(pt$t)], by = 0.001)) ## Not run: pt.plot(pt) pt.plot(pt2) ## End(Not run)
pt <- pt.sample() pt <- pt.Hz2ST(pt, ref = 100) # conversion of Hz to Semitones, reference 0 ST = 100 Hz. pt2 <- pt.interpolate(pt, seq(pt$t[1], pt$t[length(pt$t)], by = 0.001)) ## Not run: pt.plot(pt) pt.plot(pt2) ## End(Not run)
Interpolate the PitchTier in npoints
equidistant points and approximate it by Legendre polynomials
pt.legendre(pt, npoints = 1000, npolynomials = 4)
pt.legendre(pt, npoints = 1000, npolynomials = 4)
pt |
PitchTier object |
npoints |
Number of points of PitchTier interpolation |
npolynomials |
Number of polynomials to be used for Legendre modelling |
Vector of Legendre polynomials coefficients
pt.legendreSynth
, pt.legendreDemo
, pt.cut
, pt.cut0
, pt.read
, pt.plot
, pt.Hz2ST
, pt.interpolate
pt <- pt.sample() pt <- pt.Hz2ST(pt) pt <- pt.cut(pt, tStart = 3) # cut PitchTier from t = 3 sec and preserve time c <- pt.legendre(pt) print(c) leg <- pt.legendreSynth(c) ptLeg <- pt ptLeg$t <- seq(ptLeg$tmin, ptLeg$tmax, length.out = length(leg)) ptLeg$f <- leg ## Not run: plot(pt$t, pt$f, xlab = "Time (sec)", ylab = "F0 (ST re 100 Hz)") lines(ptLeg$t, ptLeg$f, col = "blue") ## End(Not run)
pt <- pt.sample() pt <- pt.Hz2ST(pt) pt <- pt.cut(pt, tStart = 3) # cut PitchTier from t = 3 sec and preserve time c <- pt.legendre(pt) print(c) leg <- pt.legendreSynth(c) ptLeg <- pt ptLeg$t <- seq(ptLeg$tmin, ptLeg$tmax, length.out = length(leg)) ptLeg$f <- leg ## Not run: plot(pt$t, pt$f, xlab = "Time (sec)", ylab = "F0 (ST re 100 Hz)") lines(ptLeg$t, ptLeg$f, col = "blue") ## End(Not run)
Plots first four Legendre polynomials
pt.legendreDemo()
pt.legendreDemo()
pt.legendre
, pt.legendreSynth
, pt.read
, pt.plot
, pt.Hz2ST
, pt.interpolate
## Not run: pt.legendreDemo() ## End(Not run)
## Not run: pt.legendreDemo() ## End(Not run)
Synthetize the contour from vector of Legendre polynomials c
in npoints
equidistant points
pt.legendreSynth(c, npoints = 1000)
pt.legendreSynth(c, npoints = 1000)
c |
Vector of Legendre polynomials coefficients |
npoints |
Number of points of PitchTier interpolation |
Vector of values of synthetized contour
pt.legendre
, pt.legendreDemo
, pt.read
, pt.plot
, pt.Hz2ST
, pt.interpolate
pt <- pt.sample() pt <- pt.Hz2ST(pt) pt <- pt.cut(pt, tStart = 3) # cut PitchTier from t = 3 sec and preserve time c <- pt.legendre(pt) print(c) leg <- pt.legendreSynth(c) ptLeg <- pt ptLeg$t <- seq(ptLeg$tmin, ptLeg$tmax, length.out = length(leg)) ptLeg$f <- leg ## Not run: plot(pt$t, pt$f, xlab = "Time (sec)", ylab = "F0 (ST re 100 Hz)") lines(ptLeg$t, ptLeg$f, col = "blue") ## End(Not run)
pt <- pt.sample() pt <- pt.Hz2ST(pt) pt <- pt.cut(pt, tStart = 3) # cut PitchTier from t = 3 sec and preserve time c <- pt.legendre(pt) print(c) leg <- pt.legendreSynth(c) ptLeg <- pt ptLeg$t <- seq(ptLeg$tmin, ptLeg$tmax, length.out = length(leg)) ptLeg$f <- leg ## Not run: plot(pt$t, pt$f, xlab = "Time (sec)", ylab = "F0 (ST re 100 Hz)") lines(ptLeg$t, ptLeg$f, col = "blue") ## End(Not run)
Plots interactive PitchTier using dygraphs
package.
pt.plot(pt, group = "")
pt.plot(pt, group = "")
pt |
PitchTier object |
group |
[optional] character string, name of group for dygraphs synchronization |
pt.read
, pt.Hz2ST
, pt.cut
, pt.cut0
, pt.interpolate
, pt.write
, tg.plot
, pitch.plot
, formant.plot
## Not run: pt <- pt.sample() pt.plot(pt) ## End(Not run)
## Not run: pt <- pt.sample() pt.plot(pt) ## End(Not run)
Reads PitchTier from Praat. Supported formats: text file, short text file, spreadsheet, headerless spreadsheet (headerless not recommended, it does not contain tmin and tmax info).
pt.read(fileNamePitchTier, encoding = "UTF-8")
pt.read(fileNamePitchTier, encoding = "UTF-8")
fileNamePitchTier |
file name of PitchTier |
encoding |
File encoding (default: |
PitchTier object
pt.write
, pt.plot
, pt.Hz2ST
, pt.cut
, pt.cut0
, pt.interpolate
, pt.legendre
, tg.read
, pitch.read
, formant.read
, it.read
, col.read
## Not run: pt <- pt.read("demo/H.PitchTier") pt.plot(pt) ## End(Not run)
## Not run: pt <- pt.read("demo/H.PitchTier") pt.plot(pt) ## End(Not run)
Saves PitchTier to a file (in UTF-8 encoding).
pt
is a list with $t
and $f
vectors (of the same length) at least.
If there are no $tmin
and $tmax
values, there are
set as min and max of $t
vector.
pt.write(pt, fileNamePitchTier, format = "spreadsheet")
pt.write(pt, fileNamePitchTier, format = "spreadsheet")
pt |
PitchTier object |
fileNamePitchTier |
file name to be created |
format |
Output file format ( |
pt.read
, tg.write
, pt.Hz2ST
, pt.interpolate
## Not run: pt <- pt.sample() pt <- pt.Hz2ST(pt) # conversion of Hz to Semitones, reference 0 ST = 100 Hz. pt.plot(pt) pt.write(pt, "demo/H_st.PitchTier") ## End(Not run)
## Not run: pt <- pt.sample() pt <- pt.Hz2ST(pt) # conversion of Hz to Semitones, reference 0 ST = 100 Hz. pt.plot(pt) pt.write(pt, "demo/H_st.PitchTier") ## End(Not run)
Rounds a number to the specified order. Round half away from zero (this is the difference from built-in round
function.)
round2(x, order = 0)
round2(x, order = 0)
x |
number to be rounded |
order |
0 (default) = units, -1 = 0.1, +1 = 10 |
rounded number to the specified order
round2(23.5) # = 24, compare: round(23.5) = 24 round2(23.4) # = 23 round2(24.5) # = 25, compare: round(24.5) = 24 round2(-23.5) # = -24, compare: round(-23.5) = -24 round2(-23.4) # = -23 round2(-24.5) # = -25, compare: round(-24.5) = -24 round2(123.456, -1) # 123.5 round2(123.456, -2) # 123.46 round2(123.456, 1) # 120 round2(123.456, 2) # 100 round2(123.456, 3) # 0 round2(-123.456, -1) # -123.5 round2(-123.456, -2) # -123.46 round2(-123.456, 1) # -120 round2(-123.456, 2) # -100 round2(-123.456, 3) # 0
round2(23.5) # = 24, compare: round(23.5) = 24 round2(23.4) # = 23 round2(24.5) # = 25, compare: round(24.5) = 24 round2(-23.5) # = -24, compare: round(-23.5) = -24 round2(-23.4) # = -23 round2(-24.5) # = -25, compare: round(-24.5) = -24 round2(123.456, -1) # 123.5 round2(123.456, -2) # 123.46 round2(123.456, 1) # 120 round2(123.456, 2) # 100 round2(123.456, 3) # 0 round2(-123.456, -1) # -123.5 round2(-123.456, -2) # -123.46 round2(-123.456, 1) # -120 round2(-123.456, 2) # -100 round2(-123.456, 3) # 0
Matlab-like behaviour of colon operator or linspace for creating sequences, for-loop friendly.
seqM(from = NA, to = NA, by = NA, length.out = NA)
seqM(from = NA, to = NA, by = NA, length.out = NA)
from |
starting value of the sequence (the first number) |
to |
end value of the sequence (the last number or the boundary number) |
by |
increment of the sequence (if specified, do not use the |
length.out |
desired length of the sequence (if specified, do not use the |
Like seq()
but with Matlab-like behavior ([: operator] with by
or [linspace] with length.out
).
If I create a for-loop, I would like to get an empty vector for 3:1
(I want a default step +1)
and also an empty vector for seq(3, 1, by = 1)
(not an error). This is solved by this seqM
function.
returns a vector of type "integer" or "double"
R: seqM | Matlab | R: seq | ||
seqM(1, 3) | [1] 1 2 3 | 1:3 | the same | the same |
seqM(1, 3, by=.8) | [1] 1.0 1.8 2.6 | 1:.8:3 | the same | the same |
seqM(1, 3, by=5) | [1] 1 | 1:5:3 | the same | the same |
seqM(3, 1) | integer(0) | 3:1 | the same | [1] 3 2 1 |
seqM(3, 1, by=+1) | integer(0) | 3:1:1 | the same | Error: wrong 'by' |
seqM(3, 1, by=-1) | [1] 3 2 1 | 3:-1:1 | the same | the same |
seqM(3, 1, by=-3) | [1] 3 | 3:-3:1 | the same | the same |
seqM(1, 3, len=5) | [1] 1.0 1.5 2.0 2.5 3.0 | linspace(1,3,5) | the same | the same |
seqM(1, 3, len=3) | [1] 1 2 3 | linspace(1,3,3) | the same | the same |
seqM(1, 3, len=2) | [1] 1 3 | linspace(1,3,2) | the same | the same |
seqM(1, 3, len=1) | [1] 3 | linspace(1,3,1) | the same | [1] 1 |
seqM(1, 3, len=0) | integer(0) + warning | linspace(1,3,0) | the same without warning | the same without warning |
seqM(3, 1, len=3) | [1] 3 2 1 | linspace(3,1,3) | the same | the same |
seqM(1, 3) seqM(1, 3, by=.8) seqM(1, 3, by=5) seqM(3, 1) seqM(3, 1, by=+1) seqM(3, 1, by=-1) seqM(3, 1, by=-3) seqM(1, 3, len=5) seqM(1, 3, len=3) seqM(1, 3, len=2) seqM(1, 3, len=1) seqM(1, 3, len=0) seqM(3, 1, len=3)
seqM(1, 3) seqM(1, 3, by=.8) seqM(1, 3, by=5) seqM(3, 1) seqM(3, 1, by=+1) seqM(3, 1, by=-1) seqM(3, 1, by=-3) seqM(1, 3, len=5) seqM(1, 3, len=3) seqM(1, 3, len=2) seqM(1, 3, len=1) seqM(1, 3, len=0) seqM(3, 1, len=3)
Cut the specified interval from the Sound object and preserve time
snd.cut(snd, Start = -Inf, End = Inf, units = "seconds")
snd.cut(snd, Start = -Inf, End = Inf, units = "seconds")
snd |
Sound object (list with |
Start |
beginning sample/time of interval to be cut (default |
End |
final sample/time of interval to be cut (default |
units |
Units of |
Sound object
snd.cut0
, tg.cut
, tg.cut0
, snd.read
, snd.plot
snd <- snd.sample() snd2 <- snd.cut(snd, Start = 0.3) snd2_0 <- snd.cut0(snd, Start = 0.3) snd3 <- snd.cut(snd, Start = 0.2, End = 0.3) snd3_0 <- snd.cut0(snd, Start = 0.2, End = 0.3) snd4 <- snd.cut(snd, End = 0.1) snd4_0 <- snd.cut0(snd, End = 0.1) snd5 <- snd.cut(snd, Start = -0.1, End = 0.1) snd5_0 <- snd.cut0(snd, Start = -0.1, End = 0.1) snd6 <- snd.cut(snd, End = 1000, units = "samples") snd6_0 <- snd.cut0(snd, End = 1000, units = "samples") ## Not run: snd.plot(snd) snd.plot(snd2) snd.plot(snd2_0) snd.plot(snd3) snd.plot(snd3_0) snd.plot(snd4) snd.plot(snd4_0) snd.plot(snd5) snd.plot(snd5_0) snd.plot(snd6) snd.plot(snd6_0) ## End(Not run)
snd <- snd.sample() snd2 <- snd.cut(snd, Start = 0.3) snd2_0 <- snd.cut0(snd, Start = 0.3) snd3 <- snd.cut(snd, Start = 0.2, End = 0.3) snd3_0 <- snd.cut0(snd, Start = 0.2, End = 0.3) snd4 <- snd.cut(snd, End = 0.1) snd4_0 <- snd.cut0(snd, End = 0.1) snd5 <- snd.cut(snd, Start = -0.1, End = 0.1) snd5_0 <- snd.cut0(snd, Start = -0.1, End = 0.1) snd6 <- snd.cut(snd, End = 1000, units = "samples") snd6_0 <- snd.cut0(snd, End = 1000, units = "samples") ## Not run: snd.plot(snd) snd.plot(snd2) snd.plot(snd2_0) snd.plot(snd3) snd.plot(snd3_0) snd.plot(snd4) snd.plot(snd4_0) snd.plot(snd5) snd.plot(snd5_0) snd.plot(snd6) snd.plot(snd6_0) ## End(Not run)
Cut the specified interval from the Sound object and and shift time so that the new snd$t[1]
= 0
snd.cut0(snd, Start = -Inf, End = Inf, units = "seconds")
snd.cut0(snd, Start = -Inf, End = Inf, units = "seconds")
snd |
Sound object (list with |
Start |
beginning sample/time of interval to be cut (default |
End |
final sample/time of interval to be cut (default |
units |
Units of |
Sound object
snd.cut
, tg.cut
, tg.cut0
, snd.read
, snd.plot
snd <- snd.sample() snd2 <- snd.cut(snd, Start = 0.3) snd2_0 <- snd.cut0(snd, Start = 0.3) snd3 <- snd.cut(snd, Start = 0.2, End = 0.3) snd3_0 <- snd.cut0(snd, Start = 0.2, End = 0.3) snd4 <- snd.cut(snd, End = 0.1) snd4_0 <- snd.cut0(snd, End = 0.1) snd5 <- snd.cut(snd, Start = -0.1, End = 0.1) snd5_0 <- snd.cut0(snd, Start = -0.1, End = 0.1) snd6 <- snd.cut(snd, End = 1000, units = "samples") snd6_0 <- snd.cut0(snd, End = 1000, units = "samples") ## Not run: snd.plot(snd) snd.plot(snd2) snd.plot(snd2_0) snd.plot(snd3) snd.plot(snd3_0) snd.plot(snd4) snd.plot(snd4_0) snd.plot(snd5) snd.plot(snd5_0) snd.plot(snd6) snd.plot(snd6_0) ## End(Not run)
snd <- snd.sample() snd2 <- snd.cut(snd, Start = 0.3) snd2_0 <- snd.cut0(snd, Start = 0.3) snd3 <- snd.cut(snd, Start = 0.2, End = 0.3) snd3_0 <- snd.cut0(snd, Start = 0.2, End = 0.3) snd4 <- snd.cut(snd, End = 0.1) snd4_0 <- snd.cut0(snd, End = 0.1) snd5 <- snd.cut(snd, Start = -0.1, End = 0.1) snd5_0 <- snd.cut0(snd, Start = -0.1, End = 0.1) snd6 <- snd.cut(snd, End = 1000, units = "samples") snd6_0 <- snd.cut0(snd, End = 1000, units = "samples") ## Not run: snd.plot(snd) snd.plot(snd2) snd.plot(snd2_0) snd.plot(snd3) snd.plot(snd3_0) snd.plot(snd4) snd.plot(snd4_0) snd.plot(snd5) snd.plot(snd5_0) snd.plot(snd6) snd.plot(snd6_0) ## End(Not run)
Returns index of sample which is nearest the given time from right, i.e.
time
<= sampleTime.
snd.getPointIndexHigherThanTime(snd, time)
snd.getPointIndexHigherThanTime(snd, time)
snd |
Sound object |
time |
time which is going to be found in samples |
integer
snd.getPointIndexNearestTime
, snd.getPointIndexLowerThanTime
snd <- snd.sample() snd.getPointIndexHigherThanTime(snd, 0.5)
snd <- snd.sample() snd.getPointIndexHigherThanTime(snd, 0.5)
Returns index of sample which is nearest the given time from left, i.e.
sampleTime <= time
.
snd.getPointIndexLowerThanTime(snd, time)
snd.getPointIndexLowerThanTime(snd, time)
snd |
Sound object |
time |
time which is going to be found in samples |
integer
snd.getPointIndexNearestTime
, snd.getPointIndexHigherThanTime
snd <- snd.sample() snd.getPointIndexLowerThanTime(snd, 0.5)
snd <- snd.sample() snd.getPointIndexLowerThanTime(snd, 0.5)
Returns index of sample which is nearest the given time
(from both sides).
snd.getPointIndexNearestTime(snd, time)
snd.getPointIndexNearestTime(snd, time)
snd |
Sound object |
time |
time which is going to be found in samples |
integer
snd.getPointIndexLowerThanTime
, snd.getPointIndexHigherThanTime
snd <- snd.sample() snd.getPointIndexNearestTime(snd, 0.5)
snd <- snd.sample() snd.getPointIndexNearestTime(snd, 0.5)
Plots interactive Sound object using dygraphs package. If the sound is 2-channel (stereo), the 1st channel is plotted around mean value +1, the 2nd around mean value -1.
snd.plot(snd, group = "", stemPlot = FALSE)
snd.plot(snd, group = "", stemPlot = FALSE)
snd |
Sound object (with |
group |
[optional] character string, name of group for dygraphs synchronization |
stemPlot |
[optional] discrete style of plot using |
## Not run: snd <- snd.sample() snd.plot(snd) snd.plot(list(sig = sin(seq(0, 2*pi, length.out = 4000)), fs = 8000)) ## End(Not run)
## Not run: snd <- snd.sample() snd.plot(snd) snd.plot(list(sig = sin(seq(0, 2*pi, length.out = 4000)), fs = 8000)) ## End(Not run)
Loads sound file (.wav or .mp3) using tuneR package.
snd.read( fileNameSound, fileType = "auto", from = 1, to = Inf, units = "samples" )
snd.read( fileNameSound, fileType = "auto", from = 1, to = Inf, units = "samples" )
fileNameSound |
Sound file name (.wav or .mp3) |
fileType |
|
from |
Where to start reading in |
to |
Where to stop reading in |
units |
Units of |
Sound object with normalized amplitude (PCM / 2^(nbits-1) - 1) resulting to the range of [-1; +1]. In fact, the minimum value can be one quantization step lower (e.g. PCM 16bit: -32768).
t
... vector of discrete time instances (seconds)
sig
... signal matrix (nrow(snd$sig)
= number of samples, ncol(snd$sig)
= number of channels, i.e., $sig[, 1]
... 1st channel)
fs
... sample rate (Hz)
nChannels
... number of signal channels (ncol(snd$sig)
), 1 == mono, 2 == stereo
nBits
... number of bits ped one sample
nSamples
... number of samples (nrow(snd$sig)
)
duration
... duration of signal (seconds), snd$duration == snd$nSamples/snd$fs
snd.write
, snd.plot
, snd.cut
, snd.getPointIndexNearestTime
## Not run: snd <- snd.read("demo/H.wav") snd.plot(snd) ## End(Not run)
## Not run: snd <- snd.read("demo/H.wav") snd.plot(snd) ## End(Not run)
Returns sample Sound object.
snd.sample()
snd.sample()
snd
snd <- snd.sample() snd.plot(snd)
snd <- snd.sample() snd.plot(snd)
Saves Sound object to a file.
snd is a list with $sig
and $fs
members at least. If $nBits
is not present, default value of 16 bits is used. Vector $t
is ignored. If the sound signal is 2-channel (stereo),
$sig
must be a two-column matrix (1st column corresponds to the left channel, 2nd column to the right channel).
If the sound is 1-channel (mono), $sig
can be either a numeric vector or a one-column matrix.
optional $t
, $nChannels
, $nSamples
, $duration
vectors are ignored.
snd.write(snd, fileNameSound)
snd.write(snd, fileNameSound)
snd |
Sound object (with |
fileNameSound |
file name to be created |
## Not run: snd <- snd.sample() snd.plot(snd) snd.write(snd, "temp1.wav") signal <- 0.8*sin(seq(0, 2*pi*440, length.out = 8000)) snd.write(list(sig = signal, fs = 8000, nBits = 16), "temp2.wav") left <- 0.3*sin(seq(0, 2*pi*440, length.out = 4000)) right <- 0.5*sin(seq(0, 2*pi*220, length.out = 4000)) snd.write(list(sig = matrix(c(left, right), ncol = 2), fs = 8000, nBits = 16), "temp3.wav") ## End(Not run)
## Not run: snd <- snd.sample() snd.plot(snd) snd.write(snd, "temp1.wav") signal <- 0.8*sin(seq(0, 2*pi*440, length.out = 8000)) snd.write(list(sig = signal, fs = 8000, nBits = 16), "temp2.wav") left <- 0.3*sin(seq(0, 2*pi*440, length.out = 4000)) right <- 0.5*sin(seq(0, 2*pi*220, length.out = 4000)) snd.write(list(sig = matrix(c(left, right), ncol = 2), fs = 8000, nBits = 16), "temp3.wav") ## End(Not run)
Find string in another string (without regular expressions), returns TRUE
/ FALSE
.
str_contains(string, patternNoRegex)
str_contains(string, patternNoRegex)
string |
string in which we try to find something |
patternNoRegex |
string we want to find, "as it is" - no regular exprressions |
TRUE
/ FALSE
str_contains("Hello world", "wor") # TRUE str_contains("Hello world", "WOR") # FALSE str_contains(tolower("Hello world"), tolower("wor")) # TRUE str_contains("Hello world", "") # TRUE
str_contains("Hello world", "wor") # TRUE str_contains("Hello world", "WOR") # FALSE str_contains(tolower("Hello world"), tolower("wor")) # TRUE str_contains("Hello world", "") # TRUE
Find string in another string (without regular expressions), returns indices of all occurences.
str_find(string, patternNoRegex)
str_find(string, patternNoRegex)
string |
string in which we try to find something |
patternNoRegex |
string we want to find, "as it is" - no regular exprressions |
indices of all occurences (1
= 1st character)
str_find1
, str_contains
, isString
str_find("Hello, hello, hello world", "ell") # 2 9 16 str_find("Hello, hello, hello world", "q") # integer(0)
str_find("Hello, hello, hello world", "ell") # 2 9 16 str_find("Hello, hello, hello world", "q") # integer(0)
Find string in another string (without regular expressions), returns indices of the first occurence only.
str_find1(string, patternNoRegex)
str_find1(string, patternNoRegex)
string |
string in which we try to find something |
patternNoRegex |
string we want to find, "as it is" - no regular exprressions |
index of the first occurence only (1
= 1st character)
str_find
, str_contains
, isString
str_find1("Hello, hello, hello world", "ell") # 2 str_find1("Hello, hello, hello world", "q") # integer(0)
str_find1("Hello, hello, hello world", "ell") # 2 str_find1("Hello, hello, hello world", "q") # integer(0)
Trim leading and trailing whitespace in character string.
strTrim(string)
strTrim(string)
string |
character string |
Like str_trim()
in stringr
package or trimws()
in R3.2.0 but way faster.
Source: Hadley Wickham comment at https://stackoverflow.com/questions/2261079/how-to-trim-leading-and-trailing-whitespace-in-r
returns a character string with removed leading and trailing whitespace characters.
isString
for testing whether it is 1 character vector, str_contains
for finding string in string without regexp, str_find
for all indices without regexp, str_find1
for the first index withoud regexp.
strTrim(" Hello World! ")
strTrim(" Hello World! ")
Aligns boundaries of intervals in the target tier (typically: "word") to the closest boundaries in the pattern tier (typically: "phone"). If there is no boundary within the tolerance limit in the pattern tier, the boundary position in the target tier is kept at its original position.
tg.boundaryMagnet( tg, targetTier, patternTier, boundaryTolerance = Inf, verbose = TRUE )
tg.boundaryMagnet( tg, targetTier, patternTier, boundaryTolerance = Inf, verbose = TRUE )
tg |
TextGrid object |
targetTier |
index or "name" of the tier to be aligned |
patternTier |
index or "name" of the pattern tier |
boundaryTolerance |
if there is not any boundary in the pattern tier within this tolerance, the target boundary is kept at its position [default: |
verbose |
if TRUE, every boundary shift is printed [default: |
TextGrid object
tg.insertBoundary
, tg.insertInterval
, tg.duplicateTier
## Not run: tg <- tg.sample() tg <- tg.removeTier(tg, "phoneme") tg <- tg.removeTier(tg, "syllable") tg <- tg.removeTier(tg, "phrase") # garble times in "word" tier a little n <- length(tg$word$label) deltaT <- runif(n - 1, min = -0.01, max = 0.015) tg$word$t2[1: (n-1)] <- tg$word$t2[1: (n-1)] + deltaT tg$word$t1[2: n] <- tg$word$t2[1: (n-1)] tg.plot(tg) # align "word" tier according to "phone tier" tg2 <- tg.boundaryMagnet(tg, targetTier = "word", patternTier = "phone") tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg <- tg.removeTier(tg, "phoneme") tg <- tg.removeTier(tg, "syllable") tg <- tg.removeTier(tg, "phrase") # garble times in "word" tier a little n <- length(tg$word$label) deltaT <- runif(n - 1, min = -0.01, max = 0.015) tg$word$t2[1: (n-1)] <- tg$word$t2[1: (n-1)] + deltaT tg$word$t1[2: n] <- tg$word$t2[1: (n-1)] tg.plot(tg) # align "word" tier according to "phone tier" tg2 <- tg.boundaryMagnet(tg, targetTier = "word", patternTier = "phone") tg.plot(tg2) ## End(Not run)
Returns tier index. Input can be either index (number) or tier name (character string). It performs checks whether the tier exists.
tg.checkTierInd(tg, tierInd)
tg.checkTierInd(tg, tierInd)
tg |
TextGrid object |
tierInd |
Tier index or "name" |
Tier index
tg.getTierName
, tg.isIntervalTier
, tg.isPointTier
, tg.plot
, tg.getNumberOfTiers
tg <- tg.sample() tg.checkTierInd(tg, 4) tg.checkTierInd(tg, "word")
tg <- tg.sample() tg.checkTierInd(tg, 4) tg.checkTierInd(tg, "word")
Returns number of labels with the specified label.
tg.countLabels(tg, tierInd, label)
tg.countLabels(tg, tierInd, label)
tg |
TextGrid object |
tierInd |
tier index or "name" |
label |
character string: label to be counted |
integer number
tg <- tg.sample() tg.countLabels(tg, "phone", "a")
tg <- tg.sample() tg.countLabels(tg, "phone", "a")
Creates new and empty TextGrid. tMin
and tMax
specify the total start
and end time for the TextGrid. If a new interval tier is added later
without specified start and end, they are set to TextGrid start and end.
tg.createNewTextGrid(tMin, tMax)
tg.createNewTextGrid(tMin, tMax)
tMin |
Start time of TextGrid |
tMax |
End time of TextGrid |
This empty TextGrid cannot be used for almost anything. At least one tier
should be inserted using tg.insertNewIntervalTier()
or tg.insertNewPointTier()
.
TextGrid object
tg.insertNewIntervalTier
, tg.insertNewPointTier
tg <- tg.createNewTextGrid(0, 5) tg <- tg.insertNewIntervalTier(tg, 1, "word") tg <- tg.insertInterval(tg, "word", 1, 2, "hello") tg.plot(tg)
tg <- tg.createNewTextGrid(0, 5) tg <- tg.insertNewIntervalTier(tg, 1, "word") tg <- tg.insertInterval(tg, "word", 1, 2, "hello") tg.plot(tg)
Cut the specified time frame from the TextGrid and preserve time
tg.cut(tg, tStart = -Inf, tEnd = Inf)
tg.cut(tg, tStart = -Inf, tEnd = Inf)
tg |
TextGrid object |
tStart |
beginning time of time frame to be cut (default |
tEnd |
final time of time frame to be cut (default |
TextGrid object
tg.cut0
, pt.cut
, pt.cut0
, tg.read
, tg.plot
, tg.write
, tg.insertInterval
tg <- tg.sample() tg2 <- tg.cut(tg, tStart = 3) tg2_0 <- tg.cut0(tg, tStart = 3) tg3 <- tg.cut(tg, tStart = 2, tEnd = 3) tg3_0 <- tg.cut0(tg, tStart = 2, tEnd = 3) tg4 <- tg.cut(tg, tEnd = 1) tg4_0 <- tg.cut0(tg, tEnd = 1) tg5 <- tg.cut(tg, tStart = -1, tEnd = 5) tg5_0 <- tg.cut0(tg, tStart = -1, tEnd = 5) ## Not run: tg.plot(tg) tg.plot(tg2) tg.plot(tg2_0) tg.plot(tg3) tg.plot(tg3_0) tg.plot(tg4) tg.plot(tg4_0) tg.plot(tg5) tg.plot(tg5_0) ## End(Not run)
tg <- tg.sample() tg2 <- tg.cut(tg, tStart = 3) tg2_0 <- tg.cut0(tg, tStart = 3) tg3 <- tg.cut(tg, tStart = 2, tEnd = 3) tg3_0 <- tg.cut0(tg, tStart = 2, tEnd = 3) tg4 <- tg.cut(tg, tEnd = 1) tg4_0 <- tg.cut0(tg, tEnd = 1) tg5 <- tg.cut(tg, tStart = -1, tEnd = 5) tg5_0 <- tg.cut0(tg, tStart = -1, tEnd = 5) ## Not run: tg.plot(tg) tg.plot(tg2) tg.plot(tg2_0) tg.plot(tg3) tg.plot(tg3_0) tg.plot(tg4) tg.plot(tg4_0) tg.plot(tg5) tg.plot(tg5_0) ## End(Not run)
Cut the specified time frame from the TextGrid and shift time so that the new tmin = 0
tg.cut0(tg, tStart = -Inf, tEnd = Inf)
tg.cut0(tg, tStart = -Inf, tEnd = Inf)
tg |
TextGrid object |
tStart |
beginning time of time frame to be cut (default |
tEnd |
final time of time frame to be cut (default |
TextGrid object
tg.cut
, pt.cut
, pt.cut0
, tg.read
, tg.plot
, tg.write
, tg.insertInterval
tg <- tg.sample() tg2 <- tg.cut(tg, tStart = 3) tg2_0 <- tg.cut0(tg, tStart = 3) tg3 <- tg.cut(tg, tStart = 2, tEnd = 3) tg3_0 <- tg.cut0(tg, tStart = 2, tEnd = 3) tg4 <- tg.cut(tg, tEnd = 1) tg4_0 <- tg.cut0(tg, tEnd = 1) tg5 <- tg.cut(tg, tStart = -1, tEnd = 5) tg5_0 <- tg.cut0(tg, tStart = -1, tEnd = 5) ## Not run: tg.plot(tg) tg.plot(tg2) tg.plot(tg2_0) tg.plot(tg3) tg.plot(tg3_0) tg.plot(tg4) tg.plot(tg4_0) tg.plot(tg5) tg.plot(tg5_0) ## End(Not run)
tg <- tg.sample() tg2 <- tg.cut(tg, tStart = 3) tg2_0 <- tg.cut0(tg, tStart = 3) tg3 <- tg.cut(tg, tStart = 2, tEnd = 3) tg3_0 <- tg.cut0(tg, tStart = 2, tEnd = 3) tg4 <- tg.cut(tg, tEnd = 1) tg4_0 <- tg.cut0(tg, tEnd = 1) tg5 <- tg.cut(tg, tStart = -1, tEnd = 5) tg5_0 <- tg.cut0(tg, tStart = -1, tEnd = 5) ## Not run: tg.plot(tg) tg.plot(tg2) tg.plot(tg2_0) tg.plot(tg3) tg.plot(tg3_0) tg.plot(tg4) tg.plot(tg4_0) tg.plot(tg5) tg.plot(tg5_0) ## End(Not run)
Duplicates tier originalInd
to new tier with specified index newInd
(existing tiers are shifted).
It is highly recommended to set a name to the new tier
(this can also be done later by tg.setTierName()
). Otherwise, both original and new tiers have the
same name which is permitted but not recommended. In such a case, we
cannot use the comfort of using tier name instead of its index in other
functions.
tg.duplicateTier(tg, originalInd, newInd = Inf, newTierName = "")
tg.duplicateTier(tg, originalInd, newInd = Inf, newTierName = "")
tg |
TextGrid object |
originalInd |
tier index or "name" |
newInd |
new tier index ( |
newTierName |
[optional but recommended] name of the new tier |
TextGrid object
tg.duplicateTierMergeSegments
, tg.setTierName
, tg.removeTier
, tg.boundaryMagnet
tg <- tg.sample() tg2 <- tg.duplicateTier(tg, "word", 1, "NEW") tg.plot(tg2)
tg <- tg.sample() tg2 <- tg.duplicateTier(tg, "word", 1, "NEW") tg.plot(tg2)
Duplicate tier originalInd
and merge segments (according to the pattern) to the new tier with specified index newInd
(existing tiers are shifted).
Typical use: create new syllable tier from phone tier. It merges phones into syllables according to separators in pattern.
tg.duplicateTierMergeSegments( tg, originalInd, newInd = Inf, newTierName, pattern, sep = "-" )
tg.duplicateTierMergeSegments( tg, originalInd, newInd = Inf, newTierName, pattern, sep = "-" )
tg |
TextGrid object |
originalInd |
tier index or "name" |
newInd |
new tier index ( |
newTierName |
name of the new tier |
pattern |
merge segments pattern for the new tier (e.g., |
sep |
separator in pattern (default: |
Note 1: there can be segments with empty labels in the original tier (pause), do not specify them in the pattern
Note 2: if there is an segment with empty label in the original tier in the place of separator in the pattern, the empty segment is duplicated into the new tier, i.e. at the position of the separator, there may or may not be an empty segment, if there is, it is duplicated. And they are not specified in the pattern.
Note 3: if the segment with empty label is not at the position corresponding to separator, it leads to error - the part specified in the pattern between separators cannot be split by empty segments
Note 4: beware of labels that appear empty but they are not (space, new line character etc.) - these segments are handled
as classical non-empty labels. See example - one label is " "
, therefore it must be specified in the pattern.
TextGrid object
tg.duplicateTier
, tg.setTierName
, tg.removeTier
tg <- tg.sample() tg <- tg.removeTier(tg, "syllable") collapsed <- paste0(tg$phone$label, collapse = "") # get actual labels print(collapsed) # all labels in collapsed form - copy the string, include separators -> pattern pattern <- "ja:-ci-P\\ek-nu-t_so-?u-J\\e-la:S- -nej-dP\\i:f-naj-deZ-h\\ut_S-ku-?a-?a-ta-ma-na:" tg2 <- tg.duplicateTierMergeSegments(tg, "phone", 1, "syll", pattern, sep = "-") ## Not run: tg.plot(tg) tg.plot(tg2) ## End(Not run)
tg <- tg.sample() tg <- tg.removeTier(tg, "syllable") collapsed <- paste0(tg$phone$label, collapse = "") # get actual labels print(collapsed) # all labels in collapsed form - copy the string, include separators -> pattern pattern <- "ja:-ci-P\\ek-nu-t_so-?u-J\\e-la:S- -nej-dP\\i:f-naj-deZ-h\\ut_S-ku-?a-?a-ta-ma-na:" tg2 <- tg.duplicateTierMergeSegments(tg, "phone", 1, "syll", pattern, sep = "-") ## Not run: tg.plot(tg) tg.plot(tg2) ## End(Not run)
Find label or consecutive sequence of labels and returns their indices.
tg.findLabels(tg, tierInd, labelVector, returnTime = FALSE)
tg.findLabels(tg, tierInd, labelVector, returnTime = FALSE)
tg |
TextGrid object |
tierInd |
tier index or "name" |
labelVector |
character string (one label) or vector of character strings (consecutive sequence of labels) to be found |
returnTime |
If |
If returnTime == FALSE
, returns list of all occurrences, each member of the list is one occurence and contains vector of label indices, if returnTime == TRUE
, returns list witch vectors t1 (begin) and t2 (end) for each found group of sequence of labels.
tg.countLabels
, tg.getLabel
, tg.duplicateTierMergeSegments
tg <- tg.sample() i <- tg.findLabels(tg, "phoneme", "n") i length(i) i[[1]] i[[2]] tg$phoneme$label[unlist(i)] i <- tg.findLabels(tg, "phone", c("?", "a")) i length(i) tg$phone$label[i[[1]]] tg$phone$label[i[[2]]] tg$phone$label[unlist(i)] t <- tg.findLabels(tg, "phone", c("?", "a"), returnTime = TRUE) t t$t2[1] - t$t1[1] # duration of the first result t$t2[2] - t$t1[2] # duration of the second result i <- tg.findLabels(tg.sample(), "word", c("ti", "reknu", "co")) i length(i) length(i[[1]]) i[[1]] i[[1]][3] tg$word$label[i[[1]]] t <- tg.findLabels(tg.sample(), "word", c("ti", "reknu", "co"), returnTime = TRUE) pt <- pt.sample() tStart <- t$t1[1] tEnd <- t$t2[1] ## Not run: pt.plot(pt.cut(pt, tStart, tEnd)) ## End(Not run)
tg <- tg.sample() i <- tg.findLabels(tg, "phoneme", "n") i length(i) i[[1]] i[[2]] tg$phoneme$label[unlist(i)] i <- tg.findLabels(tg, "phone", c("?", "a")) i length(i) tg$phone$label[i[[1]]] tg$phone$label[i[[2]]] tg$phone$label[unlist(i)] t <- tg.findLabels(tg, "phone", c("?", "a"), returnTime = TRUE) t t$t2[1] - t$t1[1] # duration of the first result t$t2[2] - t$t1[2] # duration of the second result i <- tg.findLabels(tg.sample(), "word", c("ti", "reknu", "co")) i length(i) length(i[[1]]) i[[1]] i[[1]][3] tg$word$label[i[[1]]] t <- tg.findLabels(tg.sample(), "word", c("ti", "reknu", "co"), returnTime = TRUE) pt <- pt.sample() tStart <- t$t1[1] tEnd <- t$t2[1] ## Not run: pt.plot(pt.cut(pt, tStart, tEnd)) ## End(Not run)
Returns end time. If tier index is specified, it returns end time of the tier, if it is not specified, it returns end time of the whole TextGrid.
tg.getEndTime(tg, tierInd = 0)
tg.getEndTime(tg, tierInd = 0)
tg |
TextGrid object |
tierInd |
[optional] tier index or "name" |
numeric
tg.getStartTime
, tg.getTotalDuration
tg <- tg.sample() tg.getEndTime(tg) tg.getEndTime(tg, "phone")
tg <- tg.sample() tg.getEndTime(tg) tg.getEndTime(tg, "phone")
Return duration (i.e., end - start time) of interval in interval tier.
tg.getIntervalDuration(tg, tierInd, index)
tg.getIntervalDuration(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of interval |
numeric
tg.getIntervalStartTime
, tg.getIntervalEndTime
, tg.getIntervalIndexAtTime
, tg.findLabels
tg <- tg.sample() tg.getIntervalDuration(tg, "phone", 5)
tg <- tg.sample() tg.getIntervalDuration(tg, "phone", 5)
Return end time of interval in interval tier.
tg.getIntervalEndTime(tg, tierInd, index)
tg.getIntervalEndTime(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of interval |
numeric
tg.getIntervalStartTime
, tg.getIntervalDuration
, tg.getIntervalIndexAtTime
, tg.findLabels
tg <- tg.sample() tg.getIntervalEndTime(tg, "phone", 5)
tg <- tg.sample() tg.getIntervalEndTime(tg, "phone", 5)
Returns index of interval which includes the given time, i.e.
tStart <= time
< tEnd. Tier index must belong to interval tier.
tg.getIntervalIndexAtTime(tg, tierInd, time)
tg.getIntervalIndexAtTime(tg, tierInd, time)
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time which is going to be found in intervals |
integer
tg.getIntervalStartTime
, tg.getIntervalEndTime
, tg.getLabel
, tg.findLabels
tg <- tg.sample() tg.getIntervalIndexAtTime(tg, "word", 0.5)
tg <- tg.sample() tg.getIntervalIndexAtTime(tg, "word", 0.5)
Returns start time of interval in interval tier.
tg.getIntervalStartTime(tg, tierInd, index)
tg.getIntervalStartTime(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of interval |
numeric
tg.getIntervalEndTime
, tg.getIntervalDuration
, tg.getIntervalIndexAtTime
, tg.findLabels
tg <- tg.sample() tg.getIntervalStartTime(tg, "phone", 5)
tg <- tg.sample() tg.getIntervalStartTime(tg, "phone", 5)
Return label of point or interval at the specified index.
tg.getLabel(tg, tierInd, index)
tg.getLabel(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of point or interval |
character string
tg.setLabel
, tg.countLabels
, tg.findLabels
tg <- tg.sample() tg.getLabel(tg, "phoneme", 4) tg.getLabel(tg, "phone", 4)
tg <- tg.sample() tg.getLabel(tg, "phoneme", 4) tg.getLabel(tg, "phone", 4)
Returns number of intervals in the given interval tier.
tg.getNumberOfIntervals(tg, tierInd)
tg.getNumberOfIntervals(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
integer
tg <- tg.sample() tg.getNumberOfIntervals(tg, "phone")
tg <- tg.sample() tg.getNumberOfIntervals(tg, "phone")
Returns number of points in the given point tier.
tg.getNumberOfPoints(tg, tierInd)
tg.getNumberOfPoints(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
integer
tg <- tg.sample() tg.getNumberOfPoints(tg, "phoneme")
tg <- tg.sample() tg.getNumberOfPoints(tg, "phoneme")
Returns number of tiers.
tg.getNumberOfTiers(tg)
tg.getNumberOfTiers(tg)
tg |
TextGrid object |
integer
tg.getTierName
, tg.isIntervalTier
, tg.isPointTier
tg <- tg.sample() tg.getNumberOfTiers(tg)
tg <- tg.sample() tg.getNumberOfTiers(tg)
Returns index of point which is nearest the given time from right, i.e.
time
<= pointTime. Tier index must belong to point tier.
tg.getPointIndexHigherThanTime(tg, tierInd, time)
tg.getPointIndexHigherThanTime(tg, tierInd, time)
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time which is going to be found in points |
integer
tg.getPointIndexNearestTime
, tg.getPointIndexLowerThanTime
, tg.getLabel
, tg.findLabels
tg <- tg.sample() tg.getPointIndexHigherThanTime(tg, "phoneme", 0.5)
tg <- tg.sample() tg.getPointIndexHigherThanTime(tg, "phoneme", 0.5)
Returns index of point which is nearest the given time from left, i.e.
pointTime <= time
. Tier index must belong to point tier.
tg.getPointIndexLowerThanTime(tg, tierInd, time)
tg.getPointIndexLowerThanTime(tg, tierInd, time)
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time which is going to be found in points |
integer
tg.getPointIndexNearestTime
, tg.getPointIndexHigherThanTime
, tg.getLabel
, tg.findLabels
tg <- tg.sample() tg.getPointIndexLowerThanTime(tg, "phoneme", 0.5)
tg <- tg.sample() tg.getPointIndexLowerThanTime(tg, "phoneme", 0.5)
Returns index of point which is nearest the given time
(from both sides).
Tier index must belong to point tier.
tg.getPointIndexNearestTime(tg, tierInd, time)
tg.getPointIndexNearestTime(tg, tierInd, time)
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time which is going to be found in points |
integer
tg.getPointIndexLowerThanTime
, tg.getPointIndexHigherThanTime
, tg.getLabel
, tg.findLabels
tg <- tg.sample() tg.getPointIndexNearestTime(tg, "phoneme", 0.5)
tg <- tg.sample() tg.getPointIndexNearestTime(tg, "phoneme", 0.5)
Return time of point at the specified index in point tier.
tg.getPointTime(tg, tierInd, index)
tg.getPointTime(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of point |
numeric
tg.getLabel
, tg.getPointIndexNearestTime
, tg.getPointIndexLowerThanTime
,
tg.getPointIndexHigherThanTime
, tg.findLabels
tg <- tg.sample() tg.getPointTime(tg, "phoneme", 4)
tg <- tg.sample() tg.getPointTime(tg, "phoneme", 4)
Returns start time. If tier index is specified, it returns start time of the tier, if it is not specified, it returns start time of the whole TextGrid.
tg.getStartTime(tg, tierInd = 0)
tg.getStartTime(tg, tierInd = 0)
tg |
TextGrid object |
tierInd |
[optional] tier index or "name" |
numeric
tg.getEndTime
, tg.getTotalDuration
tg <- tg.sample() tg.getStartTime(tg) tg.getStartTime(tg, "phone")
tg <- tg.sample() tg.getStartTime(tg) tg.getStartTime(tg, "phone")
Returns name of the tier.
tg.getTierName(tg, tierInd)
tg.getTierName(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
character string
tg.setTierName
, tg.isIntervalTier
, tg.isPointTier
tg <- tg.sample() tg.getTierName(tg, 2)
tg <- tg.sample() tg.getTierName(tg, 2)
Returns total duration. If tier index is specified, it returns duration of the tier, if it is not specified, it returns total duration of the TextGrid.
tg.getTotalDuration(tg, tierInd = 0)
tg.getTotalDuration(tg, tierInd = 0)
tg |
TextGrid object |
tierInd |
[optional] tier index or "name" |
numeric
tg.getStartTime
, tg.getEndTime
tg <- tg.sample() tg.getTotalDuration(tg) tg.getTotalDuration(tg, "phone")
tg <- tg.sample() tg.getTotalDuration(tg) tg.getTotalDuration(tg, "phone")
Inserts new boundary into interval tier. This creates a new interval, to
which we can set the label
(optional argument).
tg.insertBoundary(tg, tierInd, time, label = "")
tg.insertBoundary(tg, tierInd, time, label = "")
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time of the new boundary |
label |
[optional] label of the new interval |
There are more possible situations which influence where the new label will be set.
a) New boundary into the existing interval (the most common situation): The interval is splitted into two parts. The left preserves the label of the original interval, the right is set to the new (optional) label.
b) On the left of existing interval (i.e., enlarging the tier size): The new interval starts with the new boundary and ends at the start of originally first existing interval. The label is set to the new interval.
c) On the right of existing interval (i.e., enlarging the tier size): The new interval starts at the end of originally last existing interval and ends with the new boundary. The label is set to the new interval. This is somewhat different behaviour than in a) and b) where the new label is set to the interval which is on the right of the new boundary. In c), the new label is set on the left of the new boundary. But this is the only logical possibility.
It is a nonsense to insert a boundary between existing intervals to a
position where there is no interval. This is against the basic logic of
Praat interval tiers where, at the beginning, there is one large empty
interval from beginning to the end. And then, it is divided to smaller
intervals by adding new boundaries. Nevertheless, if the TextGrid is
created by external programmes, you may rarely find such discontinuities.
In such a case, at first, use the tgRepairContinuity()
function.
TextGrid object
tg.insertInterval
, tg.removeIntervalLeftBoundary
, tg.removeIntervalRightBoundary
, tg.removeIntervalBothBoundaries
, tg.boundaryMagnet
, tg.duplicateTierMergeSegments
tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") ## Not run: tg.plot(tg2) ## End(Not run)
tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") ## Not run: tg.plot(tg2) ## End(Not run)
Inserts new interval into an empty space in interval tier: a) Into an already existing interval with empty label (most common situation because, e.g., a new interval tier has one empty interval from beginning to the end. b) Outside of existing intervals (left or right), this may create another empty interval between.
tg.insertInterval(tg, tierInd, tStart, tEnd, label = "")
tg.insertInterval(tg, tierInd, tStart, tEnd, label = "")
tg |
TextGrid object |
tierInd |
tier index or "name" |
tStart |
start time of the new interval |
tEnd |
end time of the new interval |
label |
[optional] label of the new interval |
In most cases, this function is the same as 1.) tgInsertBoundary(tEnd)
and 2.) tgInsertBoundary(tStart, "new label")
. But, additional checks are
performed: a) tStart
and tEnd
belongs to the same empty interval, or
b) both times are outside of existings intervals (both left or both right).
Intersection of the new interval with more already existing (even empty) does not make a sense and is forbidden.
In many situations, in fact, this function creates more than one interval.
E.g., let's assume an empty interval tier with one empty interval from 0 to 5 sec.
1.) We insert a new interval from 1 to 2 with label "he"
.
Result: three intervals, 0-1 ""
, 1-2 "he"
, 2-5 ""
.
2.) Then, we insert an interval from 7 to 8 with label "lot"
.
Result: five intervals, 0-1 ""
, 1-2 "he"
, 2-5 ""
, 5-7 ""
, 7-8 "lot"
Note: the empty 5-7 ""
interval is inserted because we are going
outside of the existing tier.
3.) Now, we insert a new interval exactly between 2 and 3 with label "said"
.
Result: really only one interval is created (and only the right
boundary is added because the left one already exists):
0-1 ""
, 1-2 "he"
, 2-3 "said"
, 3-5 ""
, 5-7 ""
, 7-8 "lot"
.
4.) After this, we want to insert another interval, 3 to 5: label "a"
.
In fact, this does not create any new interval at all. Instead of
that, it only sets the label to the already existing interval 3-5.
Result: 0-1 ""
, 1-2 "he"
, 2-3 "said"
, 3-5 "a"
, 5-7 ""
, 7-8 "lot"
.
This function is not implemented in Praat (6.0.14). And it is very useful
for adding separate intervals to an empty area in interval tier, e.g.,
result of voice activity detection algorithm.
On the other hand, if we want continuously add new consequential
intervals, tgInsertBoundary()
may be more useful. Because, in the
tgInsertInterval()
function, if we calculate both boundaries separately
for each interval, strange situations may happen due to numeric round-up
errors, like 3.14*5 != 15.7
. In such cases, it may be hard to obtain
precisely consequential time instances. As 3.14*5
is slightly larger than
15.7
(let's try to calculate 15.7 - 3.14*5
), if you calculate tEnd
of the
first interval as 3.14*5
and tStart
of the second interval as 15.7
, this
function refuse to create the second interval because it would be an
intersection. In the opposite case (tEnd
of the 1st: 15.7
, tStart
of the
2nd: 3.14*5
), it would create another "micro" interval between these two
slightly different time instances. Instead of that, if you insert only
one boundary using the tgInsertBoundary()
function, you are safe that
only one new interval is created. But, if you calculate the "15.7
" (no
matter how) and store in the variable and then, use this variable in
the tgInsertInterval()
function both for the tEnd
of the 1st interval and
tStart
of the 2nd interval, you are safe, it works fine.
TextGrid object
tg.insertBoundary
, tg.removeIntervalLeftBoundary
, tg.removeIntervalRightBoundary
, tg.removeIntervalBothBoundaries
, tg.boundaryMagnet
, tg.duplicateTierMergeSegments
tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") ## Not run: tg.plot(tg2) ## End(Not run)
tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") ## Not run: tg.plot(tg2) ## End(Not run)
Inserts new interval tier to the specified index (existing tiers are shifted). The new tier contains one empty interval from beginning to end. Then, if we add new boundaries, this interval is divided to smaller pieces.
tg.insertNewIntervalTier(tg, newInd = Inf, newTierName, tMin = NA, tMax = NA)
tg.insertNewIntervalTier(tg, newInd = Inf, newTierName, tMin = NA, tMax = NA)
tg |
TextGrid object |
newInd |
new tier index ( |
newTierName |
new tier name |
tMin |
[optional] start time of the new tier |
tMax |
[optional] end time of the new tier |
TextGrid object
tg.insertInterval
, tg.insertNewPointTier
, tg.duplicateTier
, tg.duplicateTierMergeSegments
, tg.removeTier
## Not run: tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") tg2 <- tg.insertNewIntervalTier(tg2, Inf, "LastTier") tg2 <- tg.insertInterval(tg2, "LastTier", 1, 3, "This is the last tier") tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg2 <- tg.insertNewIntervalTier(tg, 1, "INTERVALS") tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.8) tg2 <- tg.insertBoundary(tg2, "INTERVALS", 0.1, "Interval A") tg2 <- tg.insertInterval(tg2, "INTERVALS", 1.2, 2.5, "Interval B") tg2 <- tg.insertNewIntervalTier(tg2, Inf, "LastTier") tg2 <- tg.insertInterval(tg2, "LastTier", 1, 3, "This is the last tier") tg.plot(tg2) ## End(Not run)
Inserts new point tier to the specified index (existing tiers are shifted).
tg.insertNewPointTier(tg, newInd = Inf, newTierName)
tg.insertNewPointTier(tg, newInd = Inf, newTierName)
tg |
TextGrid object |
newInd |
new tier index ( |
newTierName |
new tier name |
TextGrid object
tg.insertPoint
, tg.insertNewIntervalTier
, tg.duplicateTier
, tg.removeTier
## Not run: tg <- tg.sample() tg2 <- tg.insertNewPointTier(tg, 1, "POINTS") tg2 <- tg.insertPoint(tg2, "POINTS", 3, "MY POINT") tg2 <- tg.insertNewPointTier(tg2, Inf, "POINTS2") # the last tier tg2 <- tg.insertPoint(tg2, "POINTS2", 2, "point in the last tier") tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg2 <- tg.insertNewPointTier(tg, 1, "POINTS") tg2 <- tg.insertPoint(tg2, "POINTS", 3, "MY POINT") tg2 <- tg.insertNewPointTier(tg2, Inf, "POINTS2") # the last tier tg2 <- tg.insertPoint(tg2, "POINTS2", 2, "point in the last tier") tg.plot(tg2) ## End(Not run)
Inserts new point to point tier of the given index.
tg.insertPoint(tg, tierInd, time, label)
tg.insertPoint(tg, tierInd, time, label)
tg |
TextGrid object |
tierInd |
tier index or "name" |
time |
time of the new point |
label |
time of the new point |
TextGrid object
tg.removePoint
, tg.insertInterval
, tg.insertBoundary
## Not run: tg <- tg.sample() tg2 <- tg.insertPoint(tg, "phoneme", 1.4, "NEW POINT") tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg2 <- tg.insertPoint(tg, "phoneme", 1.4, "NEW POINT") tg.plot(tg2) ## End(Not run)
Returns TRUE
if the tier is IntervalTier, FALSE
otherwise.
tg.isIntervalTier(tg, tierInd)
tg.isIntervalTier(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
TRUE
/ FALSE
tg.isPointTier
, tg.getTierName
, tg.findLabels
tg <- tg.sample() tg.isIntervalTier(tg, 1) tg.isIntervalTier(tg, "word")
tg <- tg.sample() tg.isIntervalTier(tg, 1) tg.isIntervalTier(tg, "word")
Returns TRUE
if the tier is PointTier, FALSE
otherwise.
tg.isPointTier(tg, tierInd)
tg.isPointTier(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
TRUE
/ FALSE
tg.isIntervalTier
, tg.getTierName
, tg.findLabels
tg <- tg.sample() tg.isPointTier(tg, 1) tg.isPointTier(tg, "word")
tg <- tg.sample() tg.isPointTier(tg, 1) tg.isPointTier(tg, "word")
Plots interactive TextGrid using dygraphs
package.
tg.plot( tg, group = "", pt = NULL, it = NULL, formant = NULL, formantScaleIntensity = TRUE, formantDrawBandwidth = TRUE, pitch = NULL, pitchScaleIntensity = TRUE, pitchShowStrength = FALSE, snd = NULL )
tg.plot( tg, group = "", pt = NULL, it = NULL, formant = NULL, formantScaleIntensity = TRUE, formantDrawBandwidth = TRUE, pitch = NULL, pitchScaleIntensity = TRUE, pitchShowStrength = FALSE, snd = NULL )
tg |
TextGrid object |
group |
[optional] character string, name of group for dygraphs synchronization |
pt |
[optional] PitchTier object |
it |
[optional] IntensityTier object |
formant |
[optional] Formant object |
formantScaleIntensity |
[optional] Point size scaled according to relative intensity |
formantDrawBandwidth |
[optional] Draw formant bandwidth |
pitch |
[optional] Pitch object |
pitchScaleIntensity |
[optional] Point size scaled according to relative intensity |
pitchShowStrength |
[optional] Show strength annotation |
snd |
[optional] Sound object |
tg.read
, pt.plot
, it.plot
, pitch.plot
## Not run: tg <- tg.sample() tg.plot(tg) tg.plot(tg.sample(), pt = pt.sample()) ## End(Not run)
## Not run: tg <- tg.sample() tg.plot(tg) tg.plot(tg.sample(), pt = pt.sample()) ## End(Not run)
Loads TextGrid from Praat in Text or Short text format (UTF-8), it handles both Interval and Point tiers. Labels can may contain quotation marks and new lines.
tg.read(fileNameTextGrid, encoding = "UTF-8")
tg.read(fileNameTextGrid, encoding = "UTF-8")
fileNameTextGrid |
Input file name |
encoding |
File encoding (default: |
TextGrid object
tg.write
, tg.plot
, tg.repairContinuity
, tg.createNewTextGrid
, tg.findLabels
, tg.duplicateTierMergeSegments
, pt.read
, pitch.read
, formant.read
, it.read
, col.read
## Not run: tg <- tg.read("demo/H.TextGrid") tg.plot(tg) ## End(Not run)
## Not run: tg <- tg.read("demo/H.TextGrid") tg.plot(tg) ## End(Not run)
Remove both left and right boundary of interval of the given index
in
Interval tier. In fact, this operation concatenate three intervals into
one (and their labels). It cannot be applied to the first and the last
interval because they contain beginning or end boundary of the tier.
E.g., let's assume interval 1-2-3. We remove both boundaries of the
2nd interval. The result is one interval 123.
If we do not want to concatenate labels (we wanted to remove the label
including its interval), we can set the label of the second interval
to the empty string ""
before this operation.
If we only want to remove the label of interval "without concatenation",
i.e., the desired result is 1-empty-3, it is not this operation of
removing boundaries. Just set the label of the second interval to the
empty string ""
.
tg.removeIntervalBothBoundaries(tg, tierInd, index)
tg.removeIntervalBothBoundaries(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of the interval |
TextGrid object
tg.removeIntervalLeftBoundary
, tg.removeIntervalRightBoundary
, tg.insertBoundary
, tg.insertInterval
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalBothBoundaries(tg, "word", 3) tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalBothBoundaries(tg, "word", 3) tg.plot(tg2) ## End(Not run)
Remove left boundary of the interval of the given index
in Interval tier.
In fact, it concatenates two intervals into one (and their labels). It
cannot be applied to the first interval because it is the start boundary
of the tier.
E.g., we have interval 1-2-3, we remove the left boundary of the 2nd
interval, the result is two intervals 12-3.
If we do not want to concatenate labels, we have to set the label
to the empty string ""
before this operation.
tg.removeIntervalLeftBoundary(tg, tierInd, index)
tg.removeIntervalLeftBoundary(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of the interval |
TextGrid object
tg.removeIntervalRightBoundary
, tg.removeIntervalBothBoundaries
, tg.insertBoundary
, tg.insertInterval
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalLeftBoundary(tg, "word", 3) tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalLeftBoundary(tg, "word", 3) tg.plot(tg2) ## End(Not run)
Remove right boundary of the interval of the given index
in Interval tier.
In fact, it concatenates two intervals into one (and their labels). It
cannot be applied to the last interval because it is the end boundary
of the tier.
E.g., we have interval 1-2-3, we remove the right boundary of the 2nd
interval, the result is two intervals 1-23.
If we do not want to concatenate labels, we have to set the label
to the empty string ""
before this operation.
tg.removeIntervalRightBoundary(tg, tierInd, index)
tg.removeIntervalRightBoundary(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of the interval |
TextGrid object
tg.removeIntervalLeftBoundary
, tg.removeIntervalBothBoundaries
, tg.insertBoundary
, tg.insertInterval
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalRightBoundary(tg, "word", 3) tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeIntervalRightBoundary(tg, "word", 3) tg.plot(tg2) ## End(Not run)
Remove point of the given index
from the point tier.
tg.removePoint(tg, tierInd, index)
tg.removePoint(tg, tierInd, index)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of point to be removed |
TextGrid object
tg.insertPoint
, tg.getNumberOfPoints
, tg.removeIntervalBothBoundaries
tg <- tg.sample() tg$phoneme$label tg2 <- tg.removePoint(tg, "phoneme", 1) tg2$phoneme$label
tg <- tg.sample() tg$phoneme$label tg2 <- tg.removePoint(tg, "phoneme", 1) tg2$phoneme$label
Removes tier of the given index.
tg.removeTier(tg, tierInd)
tg.removeTier(tg, tierInd)
tg |
TextGrid object |
tierInd |
tier index or "name" |
TextGrid object
tg.insertNewIntervalTier
, tg.insertNewPointTier
, tg.duplicateTier
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeTier(tg, "word") tg.plot(tg2) ## End(Not run)
## Not run: tg <- tg.sample() tg.plot(tg) tg2 <- tg.removeTier(tg, "word") tg.plot(tg2) ## End(Not run)
Repairs problem of continuity of T2 and T1 in interval tiers. This problem is very rare and it should not appear. However, e.g., automatic segmentation tool Prague Labeller produces random numeric round-up errors featuring, e.g., T2 of preceding interval is slightly higher than the T1 of the current interval. Because of that, the boundary cannot be manually moved in Praat edit window.
tg.repairContinuity(tg, verbose = TRUE)
tg.repairContinuity(tg, verbose = TRUE)
tg |
TextGrid object |
verbose |
[optional, default=TRUE] If |
TextGrid object
## Not run: tgProblem <- tg.sampleProblem() tgNew <- tg.repairContinuity(tgProblem) tg.write(tgNew, "demo_problem_OK.TextGrid") ## End(Not run)
## Not run: tgProblem <- tg.sampleProblem() tgNew <- tg.repairContinuity(tgProblem) tg.write(tgNew, "demo_problem_OK.TextGrid") ## End(Not run)
Returns sample TextGrid with continuity problem.
tg.sampleProblem()
tg.sampleProblem()
TextGrid
tg <- tg.sampleProblem() tg2 <- tg.repairContinuity(tg) tg2 <- tg.repairContinuity(tg2) tg.plot(tg2)
tg <- tg.sampleProblem() tg2 <- tg.repairContinuity(tg) tg2 <- tg.repairContinuity(tg2) tg.plot(tg2)
Sets (changes) label of interval or point of the given index in the interval or point tier.
tg.setLabel(tg, tierInd, index, newLabel)
tg.setLabel(tg, tierInd, index, newLabel)
tg |
TextGrid object |
tierInd |
tier index or "name" |
index |
index of interval or point |
newLabel |
new "label" |
tg <- tg.sample() tg2 <- tg.setLabel(tg, "word", 3, "New Label") tg.getLabel(tg2, "word", 3)
tg <- tg.sample() tg2 <- tg.setLabel(tg, "word", 3, "New Label") tg.getLabel(tg2, "word", 3)
Sets (changes) name of tier of the given index.
tg.setTierName(tg, tierInd, name)
tg.setTierName(tg, tierInd, name)
tg |
TextGrid object |
tierInd |
tier index or "name" |
name |
new "name" of the tier |
tg <- tg.sample() tg2 <- tg.setTierName(tg, "word", "WORDTIER") tg.getTierName(tg2, 4)
tg <- tg.sample() tg2 <- tg.setTierName(tg, "word", "WORDTIER") tg.getTierName(tg2, 4)
Saves TextGrid to the file. TextGrid may contain both interval and point
tiers (tg[[1]]
, tg[[2]]
, tg[[3]]
, etc.). If tier type is not specified in $type
,
is is assumed to be "interval"
. If specified, $type
have to be "interval"
or "point"
.
If there is no class(tg)["tmin"]
and class(tg)["tmax"]
, they are calculated as min and max of
all tiers. The file is saved in UTF-8 encoding.
tg.write(tg, fileNameTextGrid, format = "short")
tg.write(tg, fileNameTextGrid, format = "short")
tg |
TextGrid object |
fileNameTextGrid |
Output file name |
format |
Output file format ( |
## Not run: tg <- tg.sample() tg.write(tg, "demo_output.TextGrid") ## End(Not run)
## Not run: tg <- tg.sample() tg.write(tg, "demo_output.TextGrid") ## End(Not run)