|
5 | 5 |
|
6 | 6 | simple HTK & TextGrid handling for go. |
7 | 7 |
|
| 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 | + |
8 | 82 | ## example |
9 | 83 |
|
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 | +``` |
11 | 114 |
|
12 | 115 | some .lab examples taken from [kiritan_singing](https://github.com/mmorise/kiritan_singing). |
0 commit comments