# load emuR

library(emuR)
# Directory of paired wav and txt files
# (download the database from here: http://www.phonetik.uni-muenchen.de/~jmh/lehre/Rdf/testsample.zip

# this is the pathc containing paired wav files and txt files containing orthography
pathger = file.path(mypath,"testsample/german")

# verify that the path exists
dir.exists(pathger)

# List the files
list.files(file.path(mypath,"testsample/german"))
list.files(file.path(mypath,"testsample/german"), pattern="*.wav")

# Directory where the emu-database is to be stored
targetger = file.path(mypath,"gerDB")

# Covert the paired wav and txt files to an emu databases
convert_txtCollection(dbName = "gertest", 
                      sourceDir = pathger,
                      targetDir = targetger)

# the above creates an emu-datbases called
# gertest_emuDB in directory file.path(mypath, "gerDB")

# load the newly created database
db.ger = load_emuDB(file.path(targetger, "gertest_emuDB"))

# look at the utterances
serve(db.ger)

# run MAUS and build levels ORT (containing words), 
runBASwebservice_all(db.ger, "transcription",  "deu-DE")
summary(db.ger)

# get all words
w.s = query(db.ger, "ORT =~ .+")
# their constituents at the level MAU
requery_hier(db.ger, w.s, "MAU")

# the word lacht
query(db.ger, "ORT = lacht")

# all /n/ segments at the level MAU
n.s = query(db.ger, "MAU = n")

# the words in which occur
requery_hier(db.ger, n.s, "ORT")

# the segments one position to the right
requery_seq(db.ger, n.s, 1)


# duration (ms) of /n/ segments
dur(n.s)


