Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,50 @@ | ||
|
||
#include <pocketsphinx.h> | ||
|
||
#define MODELDIR "/opt/sphinx/pocket/0.7/share/pocketsphinx/model" | ||
#include <boost/thread.hpp> | ||
|
||
struct Ctx { | ||
|
||
}; | ||
|
||
struct Foo { | ||
Foo(Ctx* ctx) : _ctx(ctx) {}; | ||
void operator()(){ | ||
std::cout << "..." << std::endl; | ||
}; | ||
Ctx* _ctx; | ||
}; | ||
|
||
struct Processer processer { | ||
Processer(Ctx* ctx) : _ctx(ctx) {}; | ||
void operator()(){ | ||
std::cout << "..." << std::endl; | ||
}; | ||
Ctx* _ctx; | ||
}; | ||
|
||
struct Sender { | ||
Sender(Ctx* ctx) : _ctx(ctx) {}; | ||
void operator()() { | ||
std::cout << "running sender.." << std::endl; | ||
} | ||
Ctx* _ctx; | ||
}; | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
int main(int argc, char* argv[]) | ||
{ | ||
ps_decoder_t *ps; | ||
cmd_ln_t *config; | ||
FILE *fh; | ||
char const *hyp, *uttid; | ||
int16 buf[512]; | ||
int rv; | ||
int32 score; | ||
|
||
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", | ||
NULL); | ||
if (config == NULL) | ||
return 1; | ||
ps = ps_init(config); | ||
if (ps == NULL) | ||
return 1; | ||
|
||
fh = fopen("goforward.raw", "rb"); | ||
if (fh == NULL) { | ||
perror("Failed to open goforward.raw"); | ||
return 1; | ||
} | ||
Ctx ctx; | ||
|
||
Foo foo(&ctx); | ||
boost::thread thread(foo); | ||
|
||
Sender sender(&ctx); | ||
boost::thread sender_thread(sender); | ||
|
||
Processer processer(&ctx); | ||
boost::thread | ||
|
||
thread.join(); | ||
sender_thread.join(); | ||
|
||
rv = ps_decode_raw(ps, fh, "goforward", -1); | ||
if (rv < 0) | ||
return 1; | ||
hyp = ps_get_hyp(ps, &score, &uttid); | ||
if (hyp == NULL) | ||
return 1; | ||
printf("Recognized: %s\n", hyp); | ||
|
||
fseek(fh, 0, SEEK_SET); | ||
rv = ps_start_utt(ps, "goforward"); | ||
if (rv < 0) | ||
return 1; | ||
while (!feof(fh)) { | ||
size_t nsamp; | ||
nsamp = fread(buf, 2, 512, fh); | ||
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE); | ||
} | ||
rv = ps_end_utt(ps); | ||
if (rv < 0) | ||
return 1; | ||
hyp = ps_get_hyp(ps, &score, &uttid); | ||
if (hyp == NULL) | ||
return 1; | ||
printf("Recognized: %s\n", hyp); | ||
|
||
fclose(fh); | ||
ps_free(ps); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters