命令行默认使用内置声学与语言模型,识别效果可能一般;输入需为单通道 16-bit PCM,其他格式要先用 sox 转换;align 模式需自行去除标点和大写等文本归一化
python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip install .README 未说明显存或 GPU 要求;算法紧凑高效,面向嵌入式等资源受限场景,但未列出具体硬件型号
紧凑高效的大词汇量连续语音识别引擎,适合嵌入式与离线场景
轻量级离线语音识别引擎,用 C 写成、体积小、资源占用低,适合在嵌入式设备和移动端做实时语音转文字。
核心能力
- 用 CMake 构建 C 库并提供 Python 绑定
- 命令行支持 single、live、align 三种识别模式
- 输出逐行 JSON,含词级时间戳与置信概率
- 支持音素级和状态级强制对齐
- 通过 soxflags 与 sox 管道对接任意音频格式
容易踩的坑
- v5.1.15.1.1: Security and robustness fixes最新正式版2026-06-06 · 2026-06-06 17:27 UTC
This release includes important security fixes. All users are recommended to upgrade.
What's Changed
- fix: refcount lmath in fsg to fix memory leak in jsgf2fsg by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/477
- fix: add missing %destructor for other JSGF objects by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/476
- fix: correct potential buffer overflows in language and acoustic model loading, thank you to @damseleng for reporting
Full Changelog: https://github.com/cmusphinx/pocketsphinx/compare/v5.1.0...v5.1.1
- v5.1.05.1.0: Mostly bug fixes and a few new features2026-05-06 · 2026-05-06 14:46 UTC
查看更新说明
A lot of optimizations and CLI enhancements from @lenzo-ka - thank you!!! Also thank you to the various fuzzers who caught some ancient memory errors.
A bunch of the release process is now automated in CI/CD so this should help accelerate future bugfix releases.
What's Changed
- build(deps): bump pypa/cibuildwheel from 2.22.0 to 2.23.0 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/409
- build(deps): bump pypa/cibuildwheel from 2.23.0 to 2.23.2 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/411
- build(deps): bump pypa/cibuildwheel from 2.23.2 to 2.23.3 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/413
- build(deps): bump pypa/cibuildwheel from 2.23.3 to 3.0.1 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/418
- build(deps): bump pypa/cibuildwheel from 3.0.1 to 3.1.1 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/424
- Add command-specific help for alignment options by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/422
- Fix pocketsphinx_lm_convert failing due to missing lw/wip parameters by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/420
- Add thread-local random number generator for thread safety by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/423
- Buffer fixes and dict improvement by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/419
- Add external timestamp support to endpointer to prevent clock drift by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/421
- build(deps): bump pypa/cibuildwheel from 3.1.1 to 3.1.3 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/426
- build(deps): bump actions/checkout from 4 to 5 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/427
- Increase phone support to 256 and simplify bitvector operations by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/435
- Remove deprecated pygtkcompat dependency from livedemo.py by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/442
- Fix heap-buffer-overflow in ps_mllr_read by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/439
- Fix stack-buffer overflow in WAV chunk ID logging by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/437
- Fix null pointer dereference in ngram_model_read by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/438
- build(deps): bump actions/setup-python from 5 to 6 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/430
- build(deps): bump actions/checkout from 5 to 6 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/449
- build(deps): bump pypa/cibuildwheel from 3.1.3 to 3.3.0 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/447
- build(deps): bump actions/upload-artifact from 4 to 5 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/445
- Use WAV file sample rate unless user explicitly set samprate by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/448
- Update CMU pronunciation dictionary to latest version with deduplication by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/444
- Finally maybe fix FetchContent? by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/428
- Optimize endpointer performance by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/425
- Bump versions for 5.1.0-rc1 prerelease by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/450
- build(deps): bump pypa/cibuildwheel from 3.3.0 to 3.3.1 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/452
- build(deps): bump actions/upload-artifact from 5 to 6 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/451
- Manual pages installation by @gkarsay in https://github.com/cmusphinx/pocketsphinx/pull/458
- Document state alignment and output format by @lenzo-ka in https://github.com/
- v5.1.0rc25.1.0rc2: many bug fixespre-release2026-05-04 · 2026-05-04 19:14 UTC
查看更新说明
A final release should follow relatively soon, still working through some tweaks to the release process.
What's Changed
- build(deps): bump pypa/cibuildwheel from 3.3.0 to 3.3.1 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/452
- build(deps): bump actions/upload-artifact from 5 to 6 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/451
- Manual pages installation by @gkarsay in https://github.com/cmusphinx/pocketsphinx/pull/458
- Document state alignment and output format by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/454
- build(deps): bump pypa/cibuildwheel from 3.3.1 to 3.4.1 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/463
- build(deps): bump actions/upload-artifact from 6 to 7 by @dependabot[bot] in https://github.com/cmusphinx/pocketsphinx/pull/459
- Handle mmap failures correctly by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/469
- fix: do not allocate to skip RIFF header chunks by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/471
- Fix JSGF memory errors by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/470
- fix: use the correct maximum value for FFT size by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/472
New Contributors
- @gkarsay made their first contribution in https://github.com/cmusphinx/pocketsphinx/pull/458
Full Changelog: https://github.com/cmusphinx/pocketsphinx/compare/v5.1.0rc1...v5.1.0rc2
- v5.1.0rc15.1.0rc1: Numerous optimizations and bug fixespre-release2025-12-01 · 2025-12-01 13:26 UTC
查看更新说明
What's Changed
- Add command-specific help for alignment options by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/422
- Fix pocketsphinx_lm_convert failing due to missing lw/wip parameters by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/420
- Add thread-local random number generator for thread safety by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/423
- Buffer fixes and dict improvement by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/419
- Add external timestamp support to endpointer to prevent clock drift by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/421
- Increase phone support to 256 and simplify bitvector operations by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/435
- Remove deprecated pygtkcompat dependency from livedemo.py by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/442
- Fix heap-buffer-overflow in ps_mllr_read by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/439
- Fix stack-buffer overflow in WAV chunk ID logging by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/437
- Fix null pointer dereference in ngram_model_read by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/438
- Use WAV file sample rate unless user explicitly set samprate by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/448
- Update CMU pronunciation dictionary to latest version with deduplication by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/444
- Finally maybe fix FetchContent? by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/428
- Optimize endpointer performance by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/425
- Bump versions for 5.1.0-rc1 prerelease by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/450
Full Changelog: https://github.com/cmusphinx/pocketsphinx/compare/v5.0.4...v5.1.0rc1
- v5.0.45.0.4: Minor maintenance release2025-01-10 · 2025-01-10 14:48 UTC
查看更新说明
What's Changed
- Fix _pocketsphinx.pyx's set_alignment example by @jsalsman in https://github.com/cmusphinx/pocketsphinx/pull/385
- fix: evil version pinning must die.die.die by @dhdaines in https://github.com/cmusphinx/pocketsphinx/pull/393
- Fix typos discovered by codespell by @cclauss in https://github.com/cmusphinx/pocketsphinx/pull/404
- GitHub Actions: Add Python 3.13 to the testing by @cclauss in https://github.com/cmusphinx/pocketsphinx/pull/403
- Add a simple language model maker script by @lenzo-ka in https://github.com/cmusphinx/pocketsphinx/pull/405
- Add suggested packages to
README.mdby @cartheur
New Contributors
- @dependabot made their first contribution in https://github.com/cmusphinx/pocketsphinx/pull/379
- @jsalsman made their first contribution in https://github.com/cmusphinx/pocketsphinx/pull/385
- @cclauss made their first contribution in https://github.com/cmusphinx/pocketsphinx/pull/404
- @cartheur made their first contribution
Full Changelog: https://github.com/cmusphinx/pocketsphinx/compare/v5.0.3...v5.0.4
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
PocketSphinx 5.1.1
This is PocketSphinx, one of Carnegie Mellon University's open source large vocabulary, speaker-independent continuous speech recognition engines.
Though the algorithms and models implemented by PocketSphinx are now quite old (dating back to the 1970s in some cases!) they are still useful in many applications due to their compactness and efficiency.
The version number is strangely large because there was a "release" that people are using called 5prealpha, and we will use proper semantic versioning from now on.
Please see the LICENSE file for terms of use.
Installation
We now use CMake for building, which should give reasonable results across Linux and Windows. Not certain about Mac OS X because I don't have one of those. In addition, the audio library, which never really built or worked correctly on any platform at all, has simply been removed.
There is no longer any dependency on SphinxBase. There is no SphinxBase anymore. This is not the SphinxBase you're looking for. All your SphinxBase are belong to us.
There are some other dependencies that you may find useful in order to use the example code (though they are not strictly necessary to build and install). On Debian GNU/Linux and its derivatives (such as Raspberry Pi OS, Ubuntu, etc), you can install them with:
sudo apt install \
ffmpeg \
libasound2-dev \
libportaudio2 \
libportaudiocpp0 \
libpulse-dev \
libsox-fmt-all \
portaudio19-dev \
sox
To install the Python module in a virtual environment (replace
~/ve_pocketsphinx with the virtual environment you wish to create),
from the top level directory:
python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip install .
To install the C library and bindings (assuming you have access to
/usr/local - if not, use -DCMAKE_INSTALL_PREFIX to set a different
prefix in the first cmake command below):
cmake -S . -B build
cmake --build build
cmake --build build --target install
Usage
The pocketsphinx command-line program reads single-channel 16-bit
PCM audio from standard input or one or more files, and attempts to
recognize speech in it using the default acoustic and language model.
It accepts a large number of options which you probably don't care
about, a command which defaults to live, and one or more inputs
(except in align mode), or - to read from standard input.
If you have a single-channel WAV file called "speech.wav" and you want to recognize speech in it, you can try doing this (the results may not be wonderful):
pocketsphinx single speech.wav
If your input is in some other format I suggest converting it with
sox as described below.
The commands are as follows:
-
help: Print a long list of those options you don't care about.You can also get command-specific help by running
help <command>, for examplepocketsphinx help alignwill show alignment-specific options. -
config: Dump configuration as JSON to standard output (can be loaded with the-configoption). -
live: Detect speech segments in each input, run recognition on them (using those options you don't care about), and write the results to standard output in line-delimited JSON. I realize this isn't the prettiest format, but it sure beats XML. Each line contains a JSON object with these fields, which have short names to make the lines more readable:b: Start time in seconds, from the beginning of the streamd: Duration in secondsp: Estimated probability of the recognition result, i.e. a number between 0 and 1 representing the likelihood of the input according to the modelt: Full text of recognition resultw: List of segments (usually words), each of which in turn contains theb,d,p, andtfields, for start, end, probability, and the text of the word. If-phone_align yeshas been passed, then awfield will be present containing phone segmentations, in the same format.
-
single: Recognize each input as a single utterance, and write a JSON object in the same format described above. -
align: Force-align a single audio file to a word sequence, and write a word sequence, and write a JSON object in the same format described above. The first positional argument is the input, and all subsequent ones are concatenated to make the text, to avoid surprises if you forget to quote it. You are responsible for normalizing the text to remove punctuation, uppercase, centipedes, etc. For example:pocketsphinx align goforward.wav "go forward ten meters"By default, only word-level alignment is done. To get phone alignments, pass
-phone_align yesin the flags, e.g.:pocketsphinx -phone_align yes align audio.wav $textTo get state-level alignments, pass
-state_align yes(this automatically enables phone alignment as well):pocketsphinx -state_align yes align audio.wav $textThis will make not particularly readable output, but you can use jq to clean it up. For example, you can get just the word names and start times like this:
pocketsphinx align audio.wav $text | jq '.w[]|[.t,.b]'Or you could get the phone names and durations like this:
pocketsphinx -phone_align yes align audio.wav $text | jq '.w[]|.w[]|[.t,.d]'There are many, many other possibilities, of course.
-
soxflags: Return arguments tosoxwhich will create the appropriate input format. Note that because thesoxcommand-line is slightly quirky these must always come after the filename or-d(which tellssoxto read from the microphone). You can run live recognition like this:sox -d $(pocketsphinx soxflags) | pocketsphinx -or decode from a file named "audio.mp3" like this:
sox audio.mp3 $(pocketsphinx soxflags) | pocketsphinx -
By default only errors are printed to standard error, but if you want
more information you can pass -loglevel INFO. Partial results are
not printed, maybe they will be in the future, but don't hold your
breath.
Programming
For programming, see the examples directory for a number of examples of using the library from C and Python. You can also read the documentation for the Python API or the C API
Development
There isn't quite enough information here for potential developers, but here's a start. The C API documentation is built with Doxygen, which will be auto-detected when running CMake. If you have it installed, you can build the docs with:
cmake --build build --target docs
There is a suite of regression and unit tests, run with:
cmake --build build --target check
You can run it somewhat faster with:
cd build && ctest -j4 # or however many CPUs you want to use
Somewhat confusingly (because readthedocs needs it, I think?), the
Python API documentation is in the docs directory which has nothing
to do with the abovementioned CMake target. These use some extra
dependencies named in docs/requirements.txt. To build the
documentation first set up a virtual environment, then run make in
the docs directory, with one of its many targets (html here will
make multi-page HTML documentation):
python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip install -r docs/requirements.txt
make -C docs html
There are also Python regression tests, of course, which for some
reason require memory_profiler:
python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip install -e .
pip install memory_profiler
pytest
Most, but not all of the release process is managed with GitHub Actions, namely the "Release" and "Update API Documentation" workflows. The notable exception here is updating the version, which is done with Bump My Version.
Also, the Read The Docs pages must be updated manually, it seems (maybe this will be fixed soon).
AUTHORS
PocketSphinx is ultimately based on Sphinx-II which in turn was
based on some older systems at Carnegie Mellon University, which were
released as free software under a BSD-like license thanks to the
efforts of Kevin Lenzo. Much of the decoder in particular was written
by Ravishankar Mosur (look for "rkm" in the comments), but various
other people contributed as well, see the AUTHORS file
for more details.
David Huggins-Daines (the author of this document) is
responsible for creating PocketSphinx which added
various speed and memory optimizations, fixed-point computation, JSGF
support, portability to various platforms, and a somewhat coherent
API. He then disappeared for a while.
Nickolay Shmyrev took over maintenance for quite a long time afterwards, and a lot of code was contributed by Alexander Solovets, Vyacheslav Klimkov, and others.
Currently this is maintained by David Huggins-Daines again.