-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.go
62 lines (45 loc) · 1.22 KB
/
decoder.go
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
54
55
56
57
58
59
60
61
package pocketsphinx
/*
#cgo pkg-config: sphinxbase pocketsphinx
#include <pocketsphinx.h>
*/
import "C"
import (
"unsafe"
)
type Decoder C.ps_decoder_t
func NewDecoder(config *Config) *Decoder {
return (*Decoder)(C.ps_init((*C.cmd_ln_t)(config)))
}
func (p *Decoder) ProcessRaw(data []int16, number int32, no_search int, full_utt int) int {
searched := C.ps_process_raw((*C.ps_decoder_t)(p), (*C.int16)(unsafe.Pointer(&data[0])), C.size_t(number), C.int(no_search), C.int(full_utt))
return int(searched)
}
func (p *Decoder) GetHyp() (result string, score int, uttid string) {
var r *C.char
var s C.int32
var u *C.char
r = C.ps_get_hyp((*C.ps_decoder_t)(p), &s, &u)
result = C.GoString(r)
score = int(s)
uttid = C.GoString(u)
return
}
func (p *Decoder) StartUtt(uttid string) int {
u := C.CString(uttid)
defer C.free(unsafe.Pointer(u))
rv := C.ps_start_utt((*C.ps_decoder_t)(p), u)
return int(rv)
}
func (p *Decoder) EndUtt() int {
rv := C.ps_end_utt((*C.ps_decoder_t)(p))
return int(rv)
}
func (p *Decoder) Free() int {
res := C.ps_free((*C.ps_decoder_t)(p))
return int(res)
}
func PsArgs() (arg *Arg) {
a := C.ps_args()
return (*Arg)(a)
}