Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ else()
add_compile_options(-Wall -Wextra)
endif()

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(BUILD_SHARED_LIBS)
add_definitions(-DSPHINX_DLL)
endif()
option(FIXED_POINT "Build using fixed-point math" OFF)
if(NOT DEFAULT_RADIX)
set(DEFAULT_RADIX 12)
Expand All @@ -79,18 +75,24 @@ configure_file(config.h.in config.h)
configure_file(sphinx_config.h.in include/sphinxbase/sphinx_config.h)
add_definitions(-DHAVE_CONFIG_H)

add_subdirectory(src)
# Only build SWIG and Python if we are building the package
if(CALL_FROM_SETUP_PY)
add_subdirectory(swig)
# Python build
if(SKBUILD)
add_subdirectory(src)
add_subdirectory(cython)
else()
# Don't build or install these in Python
# C shared library build
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(BUILD_SHARED_LIBS)
add_definitions(-DSPHINX_DLL)
endif()
add_subdirectory(src)
add_subdirectory(model)
add_subdirectory(doc)
add_subdirectory(include)
add_subdirectory(programs)
add_subdirectory(test)
configure_file(pocketsphinx.pc.in pocketsphinx.pc @ONLY)
install(TARGETS pocketsphinx LIBRARY)
install(FILES ${CMAKE_BINARY_DIR}/pocketsphinx.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

2 changes: 2 additions & 0 deletions cython/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.so
model
17 changes: 17 additions & 0 deletions cython/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_package(PythonExtensions REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
find_package(Cython)

set_property(TARGET pocketsphinx PROPERTY POSITION_INDEPENDENT_CODE on)

add_cython_target(_pocketsphinx _pocketsphinx.pyx)
add_library(_pocketsphinx MODULE ${_pocketsphinx})
target_link_libraries(_pocketsphinx pocketsphinx)
target_include_directories(
_pocketsphinx PRIVATE ${PYTHON_INCLUDE_DIR}
_pocketsphinx PRIVATE ${PROJECT_SOURCE_DIR}/src
_pocketsphinx PRIVATE ${PROJECT_SOURCE_DIR}/include
_pocketsphinx PRIVATE ${CMAKE_BINARY_DIR} # for config.h
)
python_extension_module(_pocketsphinx)
install(TARGETS _pocketsphinx LIBRARY DESTINATION cython/pocketsphinx5)
183 changes: 183 additions & 0 deletions cython/_pocketsphinx.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# cython: embedsignature=True
# Copyright (c) 2008-2020 Carnegie Mellon University. All rights
# reserved.
#
# You may copy, modify, and distribute this code under the same terms
# as PocketSphinx or Python, at your convenience, as long as this
# notice is not removed.
#
# Author: David Huggins-Daines <[email protected]>

cdef extern from "sphinxbase/err.h":
cdef enum err_e:
ERR_DEBUG,
ERR_INFO,
ERR_WARN,
ERR_ERROR,
ERR_FATAL,
ERR_MAX
ctypedef err_e err_lvl_t
ctypedef void (*err_cb_f)(void* user_data, err_lvl_t lvl, const char *msg);
void err_set_callback(err_cb_f callback, void *user_data)


cdef extern from "sphinxbase/logmath.h":
ctypedef struct logmath_t:
pass

logmath_t *logmath_init(double base, int shift, int use_table)
logmath_t *logmath_retain(logmath_t *lmath)
int logmath_free(logmath_t *lmath)

int logmath_log(logmath_t *lmath, double p)
double logmath_exp(logmath_t *lmath, int p)

int logmath_ln_to_log(logmath_t *lmath, double p)
double logmath_log_to_ln(logmath_t *lmath, int p)

int logmath_log10_to_log(logmath_t *lmath, double p)
double logmath_log_to_log10(logmath_t *lmath, int p)

int logmath_add(logmath_t *lmath, int p, int q)

int logmath_get_zero(logmath_t *lmath)

cdef extern from "sphinxbase/fe.h":
ctypedef struct fe_t:
pass

cdef extern from "sphinxbase/hash_table.h":
ctypedef struct hash_table_t:
pass
ctypedef struct hash_entry_t:
const char *key
ctypedef struct hash_iter_t:
hash_entry_t *ent
hash_iter_t *hash_table_iter(hash_table_t *h)
hash_iter_t *hash_table_iter_next(hash_iter_t *h)
const char *hash_entry_key(hash_entry_t *ent)


cdef extern from "sphinxbase/cmd_ln.h":
ctypedef struct arg_t:
const char *name
int type
const char *deflt
const char *doc
ctypedef struct cmd_ln_t:
hash_table_t *ht
const arg_t *defn
cdef enum:
ARG_REQUIRED,
ARG_INTEGER,
ARG_FLOATING,
ARG_STRING,
ARG_BOOLEAN,
REQARG_INTEGER,
REQARG_FLOATING,
REQARG_STRING,
REQARG_BOOLEAN
ctypedef struct cmd_ln_val_t:
int type

cmd_ln_t *cmd_ln_parse_r(cmd_ln_t *inout_cmdln, arg_t *defn,
int argc, char **argv, int strict)
int cmd_ln_free_r(cmd_ln_t *cmdln)

double cmd_ln_float_r(cmd_ln_t *cmdln, const char *name)
int cmd_ln_type_r(cmd_ln_t *cmdln, const char *name)
long cmd_ln_int_r(cmd_ln_t *cmdln, const char *name)
const char *cmd_ln_str_r(cmd_ln_t *cmdln, const char *name)
void cmd_ln_set_str_r(cmd_ln_t *cmdln, const char *name, const char *str)
void cmd_ln_set_str_extra_r(cmd_ln_t *cmdln, const char *name, const char *str)
void cmd_ln_set_int_r(cmd_ln_t *cmdln, const char *name, long iv)
void cmd_ln_set_float_r(cmd_ln_t *cmdln, const char *name, double fv)
cmd_ln_val_t *cmd_ln_access_r(cmd_ln_t *cmdln, const char *name)

int cmd_ln_exists_r(cmd_ln_t *cmdln, const char *name)


cdef extern from "sphinxbase/fsg_model.h":
ctypedef struct fsg_model_t:
int start_state
int final_state

fsg_model_t *fsg_model_init(const char *name, logmath_t *lmath,
float lw, int n_state)
fsg_model_t *fsg_model_readfile(const char *file, logmath_t *lmath,
float lw)
const char *fsg_model_name(fsg_model_t *fsg)
int fsg_model_free(fsg_model_t *fsg)

int fsg_model_word_add(fsg_model_t *fsg, const char *word)
int fsg_model_word_id(fsg_model_t *fsg, const char *word)
void fsg_model_trans_add(fsg_model_t * fsg,
int source, int dest, int logp, int wid)
int fsg_model_null_trans_add(fsg_model_t * fsg, int source, int dest,
int logp)
int fsg_model_tag_trans_add(fsg_model_t * fsg, int source, int dest,
int logp, int wid)
void fsg_model_writefile(fsg_model_t *fsg, const char *file)


cdef extern from "sphinxbase/jsgf.h":
ctypedef struct jsgf_t:
pass
ctypedef struct jsgf_rule_t:
pass
fsg_model_t *jsgf_read_file(const char *name, logmath_t *lmath,
float lw)
jsgf_t *jsgf_parse_string(const char *string, jsgf_t *parent)
const char *jsgf_grammar_name(jsgf_t *jsgf)
void jsgf_grammar_free(jsgf_t *jsgf)
jsgf_rule_t *jsgf_get_rule(jsgf_t *grammar, const char *name)
jsgf_rule_t *jsgf_get_public_rule(jsgf_t *grammar)
fsg_model_t *jsgf_build_fsg(jsgf_t *grammar, jsgf_rule_t *rule,
logmath_t *lmath, float lw)


cdef extern from "pocketsphinx.h":
ctypedef struct ps_decoder_t:
pass
ctypedef struct ps_seg_t:
pass
ctypedef struct ps_nbest_t:
pass
ctypedef struct ps_lattice_t:
pass
arg_t *ps_args()
ps_decoder_t *ps_init(cmd_ln_t *config)
int ps_free(ps_decoder_t *ps)
int ps_reinit(ps_decoder_t *ps, cmd_ln_t *config)
int ps_reinit_feat(ps_decoder_t *ps, cmd_ln_t *config)
logmath_t *ps_get_logmath(ps_decoder_t *ps)
int ps_start_stream(ps_decoder_t *ps)
int ps_get_in_speech(ps_decoder_t *ps)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expose get_in_speech as well? That would let you do some nice things like keep a mic open but discard the. audio up to x msec before speech starts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, funny you mention this, because I had removed get_in_speech as the internal VAD, which it used, was buggy and also not a very good VAD. do you have code that uses it already? I am trying to figure out what exactly the use case is for it and whether it can be supported or not...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No -- and actually we can just check if there are word in the hyp, so I wouldn't worry about it

int ps_start_utt(ps_decoder_t *ps)
int ps_process_raw(ps_decoder_t *ps,
const short *data, size_t n_samples,
int no_search, int full_utt)
int ps_end_utt(ps_decoder_t *ps)
const char *ps_get_hyp(ps_decoder_t *ps, int *out_best_score)
int ps_get_prob(ps_decoder_t *ps)
ps_seg_t *ps_seg_iter(ps_decoder_t *ps)
ps_seg_t *ps_seg_next(ps_seg_t *seg)
const char *ps_seg_word(ps_seg_t *seg)
void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef)
int ps_seg_prob(ps_seg_t *seg, int *out_ascr, int *out_lscr, int *out_lback)
void ps_seg_free(ps_seg_t *seg)
int ps_add_word(ps_decoder_t *ps, char *word, char *phones, int update)
char *ps_lookup_word(ps_decoder_t *ps, const char *word)
int ps_set_fsg(ps_decoder_t *ps, const char *name, fsg_model_t *fsg)
int ps_set_jsgf_file(ps_decoder_t *ps, const char *name, const char *path)
int ps_set_jsgf_string(ps_decoder_t *ps, const char *name, const char *jsgf_string)
ps_nbest_t *ps_nbest(ps_decoder_t *ps)
ps_nbest_t *ps_nbest_next(ps_nbest_t *nbest)
const char *ps_nbest_hyp(ps_nbest_t *nbest, int *out_score)
ps_seg_t *ps_nbest_seg(ps_nbest_t *nbest)
void ps_nbest_free(ps_nbest_t *nbest)
ps_lattice_t *ps_get_lattice(ps_decoder_t *ps)
void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech,
double *out_ncpu, double *out_nwall)
void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech,
double *out_ncpu, double *out_nwall)
Loading