Skip to content

Commit

Permalink
Some adds in the sphinx stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kskels committed Apr 22, 2012
1 parent 914f733 commit b252470
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 63 deletions.
99 changes: 43 additions & 56 deletions src/sample/sphinx/main.cpp
@@ -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;
}

14 changes: 7 additions & 7 deletions src/sample/sphinx/wscript
Expand Up @@ -9,11 +9,11 @@ out = 'bin'
def options(opt):
opt.load('compiler_cxx')

def configure(conf):
conf.load('compiler_cxx')
def configure(ctx):
ctx.load('compiler_cxx')

# defines for sphinx
lib_sphinx = ['pocketsphinx', 'sphinxbase', 'sphinxad']
# sphinx
lib_sphinx = ['pocketsphinx', 'sphinxbase', 'sphinxad', 'boost_thread']
libpath_sphinx = ['/opt/sphinx/base/0.7/lib', '/opt/sphinx/pocket/0.7/lib']
include_sphinx = [
'/opt/sphinx/pocket/0.7/include/pocketsphinx',
Expand All @@ -22,13 +22,13 @@ include_sphinx = [
'/opt/sphinx/base/0.7/include'
]

def build(bld):
bld.program(
def build(ctx):
ctx.program(
source='main.cpp',
target='ubi',
includes = include_sphinx,
libpath = libpath_sphinx,
lib = lib_sphinx
lib = lib_sphinx
)

def dist(ctx):
Expand Down

0 comments on commit b252470

Please sign in to comment.