-
Notifications
You must be signed in to change notification settings - Fork 2
/
txt2praat.R
53 lines (47 loc) · 1.38 KB
/
txt2praat.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
txt2praat <- function(x, filename) {
# Appends the Praat header to enable txt vector to be read in Praat.
#
# Args:
# x: A path to the txt file (vector) that the header attached will be attached to.
# Example:
# >x <- file.choose()
#
# filename: Optional argument specifying the output file name
#
# Returns:
# Text file that can be loaded into Praat.
# assign the output file name
if(missing(filename)) {
# use the original file name
filename <- basename(file.path(x))
} else {
filename <- paste(deparse(substitute(filename)),
".txt",
sep = ""
)
}
# read as a vector
#x <- as.character(scan(x))
# header needed to read txt into Praat
praat_header <- c('File type = "ooTextFile"',
'Object class = "Sound 2"',
'',
'0',
'0.41',
'6536',
'0.0000610221205187',
'0.0000305110602593',
'1',
'1',
'1',
'1',
'1')
# add the header to loaded file
pf <- append(praat_header, x)
# save the output
write.table(pf,
file=filename,
quote=FALSE,
row.names=FALSE,
col.names=FALSE)
}