-
Notifications
You must be signed in to change notification settings - Fork 729
Switch back to Cython and use scikit-build for Python module #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
eb8514f
feat: Switch to Cython and scikit-build
dhdaines 6171b56
test: copy SWIG tests to Cython directory
dhdaines be8c703
build: update requirements.dev.txt
dhdaines aa4e360
fix: add lookup_word
dhdaines 7221782
build: fix build requirements
dhdaines a5e13a4
test: remove swig tests
dhdaines 1870bfe
test: fix paths
dhdaines 9b0dc72
fix: proper iterators for segment, nbest
dhdaines e5dc153
fix: small documentation fixes
dhdaines 9bb8f9b
fix: everything in decoder_test.py
dhdaines 8d289ad
fix: open filehandles in tests
dhdaines fa28e1d
feat: add LogMath and properly refcount it
dhdaines bd76942
test: fix formatting
dhdaines a300cc7
fix: support the whole test set
dhdaines 1afea3a
build: fix build and test dependencies
dhdaines ffcf30f
refactor: fix formatting
dhdaines c288639
feat: add more logical Config.parse_file() method
dhdaines 36cec5b
test: add config tests from soundswallower
dhdaines 5affa65
docs: add docstring
dhdaines 48a3da6
refactor: fix formatting
dhdaines c3f8648
fix: begone, SWIG
dhdaines 34eea3a
build: bump up version (not released yet)
dhdaines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.so | ||
| model |
This file contains hidden or 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 |
|---|---|---|
| @@ -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) |
This file contains hidden or 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 |
|---|---|---|
| @@ -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) | ||
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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