Convert Textgrid to EmuR - Hywel-Stoakes/EmuRSummerSchool GitHub Wiki
Setup
What you need
A directory with you audiofiles and textgrids in pairs (there must be exactly one pair of each).
The Function
library(emuR)
emuR::convert_TextGridCollection(dir,
dbName,
targetDir,
tgExt = "TextGrid",
audioExt = "wav",
tierNames = NULL,
verbose = TRUE)
Where:
- dir is path to directory containing the TextGridCollection in quotes (nested directory structures are ok)
- dbName, is a name for your new database (enclose in quotes)
- targetDir is Where your new database will be located
- tgExt = "TextGrid" is The exact extension of the textgrds (usually praat has this as TextGrid)
- audioExt = "wav" is the extention of the audio files
- tierNames = NULL is You can use this to pick the tier to convert (otherwise it will be all)
- verbose = TRUE is How much information is returned
An Example
### An example: From emu R help
# convert TextGridCollection and store
# new emuDB in folder provided by tempdir()
convert_TextGridCollection(dir = "/path/to/directory/",
dbName = "myTGcolDB",
targetDir = tempdir())
# same as above but this time only convert
# the information stored in the "Syllable" and "Phonetic" tiers
convert_TextGridCollection(dir = "/path/to/directory/",
dbName = "myTGcolDB",
targetDir = tempdir(),
tierNames = c("Syllable", "Phonetic"))
Once Converted to EmuDB
- load the emudb
library(emuR)
TG.db <- load_emuDB("path to your txtgridcollection") # This will take a while
# especially the first time it is run
serve(TG.db) # This will open the broswer window
# (Works best in chrome)
Creating the F0 files
F0.params <- formals(wrassp::ksvF0)
F0.params$gender <- "f"
add_ssffTrackDefinition(emuDBhandle = TG.db,
name = "F0",
onTheFlyFunctionName = "ksvF0",
onTheFlyParams = F0.params
)
list_perspectives(TG.db)
add_perspective(emuDBhandle = TG.db,
name = "Pitch")
set_signalCanvasesOrder(emuDBhandle = TG.db,
perspectiveName = "Pitch",
order = c("OSCI","SPEC","F0"))
set_levelCanvasesOrder(emuDBhandle = TG.db,
perspectiveName = "Pitch",
order = c("MAU")) # Change this to the tires you want to see in the browser
Creating formant files
Formant files are a bit trickier, so you you will have to edit the emu config JSON (see below)
fm.params <- formals(wrassp::forest)
add_ssffTrackDefinition(emuDBhandle = TG.db, # change as needed
name = "FORMANTS", # This needs to be left as FORMANTS
columnName = "fm",
fileExtension = "fms",
onTheFlyFunctionName = "forest",
onTheFlyParams = fm.params
)
list_perspectives(TG.db)
## Reload the db
TG.db <- load_emuDB("path to database")
serve(TG.db)
Then you need to open the json file that has ("_DBconfig.json") at the end and add this to the file where it says "perspectives" - usually around line 78
"perspectives": [
{
"name": "default",
"signalCanvases": {
"order": [
"OSCI",
"SPEC"
],
"assign": [
{
"signalCanvasName": "SPEC",
"ssffTrackName": "FORMANTS"
}
],
"contourLims": [
{
"ssffTrackName": "FORMANTS",
"minContourIdx": 0,
"maxContourIdx": 2
}
],
"contourColors": [
{
"ssffTrackName": "FORMANTS",
"colors": [
"rgb(17,87,209)",
"rgb(209,139,17)",
"rgb(209,17,183)"
]
}
]
},
"levelCanvases": {
"order": [
"MAU"
]
},
"twoDimCanvases": {
"order": []
}
},
{
"name": "Pitch",
"signalCanvases": {
"order": [
"OSCI",
"SPEC",
"F0"
],
"assign": [],
"contourLims": []
},
"levelCanvases": {
"order": [
"MAU"
]
},
"twoDimCanvases": {
"order": []
}
}
],
Also just below it be sure that in the restrictions that:
"restrictions": {
"showPerspectivesSidebar": true
},
Then reload the database:
## Reload the db
TG.db <- load_emuDB("path to database")
serve(TG.db)
Creating the hierarchies
autobuild_linkFromTimes(emuDBhandle,
superlevelName,
sublevelName,
rewriteAllAnnots = TRUE,
convertSuperlevel = FALSE,
backupLevelAppendStr = "-autobuildBackup",
newLinkDefType = NULL,
verbose = TRUE)
where:
- emuDBhandle is the name of the object that you have loaded your db into (we have been usung TG.db)
- superlevelName, is the name of the highest tier (usually utterance)
- sublevelName is the name of the tier that it attaces to (e.g. word)
You have to do this process for all of the levels (Please contact me or consult the Emu SDMS manual Section 7.2)