-
Notifications
You must be signed in to change notification settings - Fork 2
/
keyword.c
65 lines (46 loc) · 1.39 KB
/
keyword.c
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
62
63
64
65
#include <stdio.h>
#include <pocketsphinx.h>
// TODO: create a header file
void ps_reset(ps_decoder_t *decoder);
int main(int argc, char *argv[]) {
ps_decoder_t *decoder;
int rv;
FILE *file;
const char *KEYWORD = "forward";
int buffsize = 512;
int16 buf[buffsize]; // audio buffer
int score;
const char *uttid;
// create configuration
cmd_ln_t *config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
"-lm", MODELDIR "/lm/en/turtle.DMP",
"-dict", MODELDIR "/lm/en/turtle.dic",
"-logfn", "/dev/null", // no logs in stdout
NULL);
// instantiate decoder
decoder = ps_init(config);
// set KWS values
ps_set_keyphrase(decoder, "keywords", KEYWORD);
ps_set_search(decoder, "keywords");
// open file
file = fopen("goforward.raw", "rb");
// start listening
ps_start_utt(decoder, "spotting");
// decode audio buffer
while (!feof(file)) {
size_t nsamp = fread(buf, 2, buffsize, file);
ps_process_raw(decoder, buf, nsamp, FALSE, FALSE);
}
const char *hyp = ps_get_hyp(decoder, &score, &uttid);
if (hyp != NULL)
printf("%s \n", hyp);
ps_reset(decoder);
fclose(file);
ps_free(decoder);
return 0;
}
void ps_reset(ps_decoder_t *decoder) {
ps_end_utt(decoder);
ps_start_utt(decoder, NULL);
}