Skip to content

Commit 060252a

Browse files
committed
update docs
1 parent 38c4f2b commit 060252a

File tree

2 files changed

+107
-4
lines changed

2 files changed

+107
-4
lines changed

README.md

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,111 @@
55

66
simple HTK & TextGrid handling for go.
77

8+
## installation
9+
10+
```plaintext
11+
$ go get github.com/vocatart/golab
12+
```
13+
14+
## about HTK and TextGrid
15+
16+
[HTK](http://www.seas.ucla.edu/spapl/weichu/htkbook/node113_mn.html) and [TextGrid](https://www.fon.hum.uva.nl/praat/manual/TextGrid_file_formats.html) are two popular formats used for annotating audio, mainly for use in linguistic analysis.
17+
18+
### HTK
19+
20+
while HTK is officially defined as `[start [end] ] name [score] { auxname [auxscore] } [comment]` golab only
21+
supports HTK labels in the format `[start] [end] [name]`. Due to the non-standardization of the HTK format, it is
22+
hard to guarantee compatibility. For most linguistic applications, this should be sufficient.
23+
24+
### TextGrid
25+
26+
TextGrid files are internally stored as short format TextGrids. all other information in between the relevant data
27+
will be ignored.
28+
29+
#### tiers flag
30+
31+
TextGrid files have a flag that designate whether they contain tiers. For example, a TextGrid that contains tiers
32+
would look like the following:
33+
34+
```TextGrid
35+
File type = "ooTextFile"
36+
Object class = "TextGrid"
37+
38+
xmin = 0
39+
xmax = 2.3
40+
tiers? <exists>
41+
size = 3
42+
item []:
43+
item [1]:
44+
class = "IntervalTier"
45+
name = "Mary"
46+
xmin = 0
47+
xmax = 2.3
48+
intervals: size = 1
49+
intervals [1]:
50+
xmin = 0
51+
xmax = 2.3
52+
text = ""
53+
item [2]:
54+
class = "IntervalTier"
55+
name = "John"
56+
xmin = 0
57+
xmax = 2.3
58+
intervals: size = 1
59+
intervals [1]:
60+
xmin = 0
61+
xmax = 2.3
62+
text = ""
63+
item [3]:
64+
class = "TextTier"
65+
name = "bell"
66+
xmin = 0
67+
xmax = 2.3
68+
points: size = 0
69+
```
70+
71+
while a TextGrid with no tiers would have an `<absent>` tag instead.
72+
73+
```TextGrid
74+
File type = "ooTextFile"
75+
Object class = "TextGrid"
76+
77+
xmin = 0
78+
xmax = 2.3
79+
tiers? <absent>
80+
```
81+
882
## example
983

10-
wip
84+
```go
85+
package main
86+
87+
import (
88+
"github.com/vocatart/golab/htk"
89+
"github.com/vocatart/golab/textgrid"
90+
)
91+
92+
func main() {
93+
lab, err := htk.ReadLab("examples/short.lab")
94+
if err != nil {
95+
panic(err)
96+
}
97+
98+
lab.GetName() // returns "short"
99+
lab.GetAnnotations() // returns []Annotation
100+
lab.GetPrecision() // returns 7 (floating point precision of file, parsed when read in)
101+
// etc
102+
103+
tg, err := textgrid.ReadTextgrid("examples/long.TextGrid")
104+
if err != nil {
105+
panic(err)
106+
}
107+
108+
tg.GetXmin() // returns 0.0
109+
tg.GetXmax() // returns 2.3510204081632655
110+
tg.GetTiers() // returns []Tier (can contain IntervalTier or PointTier)
111+
tg.GetName() // returns "long"
112+
}
113+
```
11114

12115
some .lab examples taken from [kiritan_singing](https://github.com/mmorise/kiritan_singing).

textgrid/textgrid.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (tg *TextGrid) GetSize() int {
126126
// ReadTextgrid takes a path to a .TextGrid file and reads its contents into a TextGrid.
127127
func ReadTextgrid(path string) (TextGrid, error) {
128128
var tg = TextGrid{}
129-
tgDeque := deque.Deque[string]{}
129+
tgDeque := new(deque.Deque[string])
130130

131131
// grab the name element from the path
132132
tg.name = filepath.Base(path)
@@ -157,7 +157,7 @@ func ReadTextgrid(path string) (TextGrid, error) {
157157
}
158158

159159
// verify the first two entries in the deque
160-
err = verifyHead(&tgDeque)
160+
err = verifyHead(tgDeque)
161161
if err != nil {
162162
return tg, fmt.Errorf("error: textgrid %s has malformed header\n %s", tg.name, err.Error())
163163
}
@@ -192,7 +192,7 @@ func ReadTextgrid(path string) (TextGrid, error) {
192192
return tg, fmt.Errorf("error: cannot parse textgrid numTiers:\n %s", err.Error())
193193
}
194194

195-
tiers, err := parseTiers(globalXmin, globalXmax, &tgDeque, numTiers)
195+
tiers, err := parseTiers(globalXmin, globalXmax, tgDeque, numTiers)
196196
if err != nil {
197197
return tg, fmt.Errorf("error: cannot parse textgrid tiers:\n %s", err.Error())
198198
}

0 commit comments

Comments
 (0)