{"id":15009779,"url":"https://github.com/bambocher/pocketsphinx-python","last_synced_at":"2025-10-21T13:02:58.213Z","repository":{"id":21051807,"uuid":"24350788","full_name":"bambocher/pocketsphinx-python","owner":"bambocher","description":"Python interface to CMU Sphinxbase and Pocketsphinx libraries","archived":true,"fork":false,"pushed_at":"2023-06-27T09:48:50.000Z","size":25724,"stargazers_count":373,"open_issues_count":39,"forks_count":187,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-12-30T13:45:09.590Z","etag":null,"topics":["pocketsphinx","python","speech","speech-recognition","sphinxbase","voice"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/pocketsphinx","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bambocher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-09-23T00:37:01.000Z","updated_at":"2024-11-22T20:12:50.000Z","dependencies_parsed_at":"2023-10-20T18:17:17.313Z","dependency_job_id":null,"html_url":"https://github.com/bambocher/pocketsphinx-python","commit_stats":{"total_commits":178,"total_committers":5,"mean_commits":35.6,"dds":0.0561797752808989,"last_synced_commit":"769492da47e41b71e3dd57a6b033fbba79e57032"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambocher%2Fpocketsphinx-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambocher%2Fpocketsphinx-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambocher%2Fpocketsphinx-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambocher%2Fpocketsphinx-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bambocher","download_url":"https://codeload.github.com/bambocher/pocketsphinx-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235173177,"owners_count":18947452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pocketsphinx","python","speech","speech-recognition","sphinxbase","voice"],"created_at":"2024-09-24T19:28:31.819Z","updated_at":"2025-10-03T19:30:19.135Z","avatar_url":"https://github.com/bambocher.png","language":"Python","readme":"# Pocketsphinx Python\n\n[![Latest Version](https://img.shields.io/pypi/v/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx)\n[![Development Status](https://img.shields.io/pypi/status/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx)\n[![Travis Build Status](https://travis-ci.org/bambocher/pocketsphinx-python.svg?branch=master)](https://travis-ci.org/bambocher/pocketsphinx-python)\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/v2rvnt181dox00jr/branch/master?svg=true)](https://ci.appveyor.com/project/bambocher/pocketsphinx-python/branch/master)\n[![License](https://img.shields.io/pypi/l/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx)\n\n\u003e **Warning**\n\u003e This repository is no longer maintained. Please use the official python bindings for PocketSphinx: [github](https://github.com/cmusphinx/pocketsphinx), [pypi](https://pypi.org/project/pocketsphinx/).\n\nPocketsphinx is a part of the [CMU Sphinx](http://cmusphinx.sourceforge.net) Open Source Toolkit For Speech Recognition.\n\nThis package provides a python interface to CMU [Sphinxbase](https://github.com/cmusphinx/sphinxbase) and [Pocketsphinx](https://github.com/cmusphinx/pocketsphinx) libraries created with [SWIG](http://www.swig.org) and [Setuptools](https://setuptools.readthedocs.io).\n\n## Supported platforms\n\n* Windows\n* Linux\n* Mac OS X\n\n## Installation\n\n```shell\n# Make sure we have up-to-date versions of pip, setuptools and wheel\npython -m pip install --upgrade pip setuptools wheel\npip install --upgrade pocketsphinx\n```\n\nMore binary distributions for manual installation are available [here](https://pypi.org/project/pocketsphinx/#files).\n\n## Usage\n\n### LiveSpeech\n\nIt's an iterator class for continuous recognition or keyword search from a microphone.\n\n```python\nfrom pocketsphinx import LiveSpeech\nfor phrase in LiveSpeech(): print(phrase)\n```\n\nAn example of a keyword search:\n\n```python\nfrom pocketsphinx import LiveSpeech\n\nspeech = LiveSpeech(lm=False, keyphrase='forward', kws_threshold=1e-20)\nfor phrase in speech:\n    print(phrase.segments(detailed=True))\n```\n\nWith your model and dictionary:\n\n```python\nimport os\nfrom pocketsphinx import LiveSpeech, get_model_path\n\nmodel_path = get_model_path()\n\nspeech = LiveSpeech(\n    verbose=False,\n    sampling_rate=16000,\n    buffer_size=2048,\n    no_search=False,\n    full_utt=False,\n    hmm=os.path.join(model_path, 'en-us'),\n    lm=os.path.join(model_path, 'en-us.lm.bin'),\n    dic=os.path.join(model_path, 'cmudict-en-us.dict')\n)\n\nfor phrase in speech:\n    print(phrase)\n```\n\n### AudioFile\n\nIt's an iterator class for continuous recognition or keyword search from a file.\n\n```python\nfrom pocketsphinx import AudioFile\nfor phrase in AudioFile(): print(phrase) # =\u003e \"go forward ten meters\"\n```\n\nAn example of a keyword search:\n\n```python\nfrom pocketsphinx import AudioFile\n\naudio = AudioFile(lm=False, keyphrase='forward', kws_threshold=1e-20)\nfor phrase in audio:\n    print(phrase.segments(detailed=True)) # =\u003e \"[('forward', -617, 63, 121)]\"\n```\n\nWith your model and dictionary:\n\n```python\nimport os\nfrom pocketsphinx import AudioFile, get_model_path, get_data_path\n\nmodel_path = get_model_path()\ndata_path = get_data_path()\n\nconfig = {\n    'verbose': False,\n    'audio_file': os.path.join(data_path, 'goforward.raw'),\n    'buffer_size': 2048,\n    'no_search': False,\n    'full_utt': False,\n    'hmm': os.path.join(model_path, 'en-us'),\n    'lm': os.path.join(model_path, 'en-us.lm.bin'),\n    'dict': os.path.join(model_path, 'cmudict-en-us.dict')\n}\n\naudio = AudioFile(**config)\nfor phrase in audio:\n    print(phrase)\n```\n\nConvert frame into time coordinates:\n\n```python\nfrom pocketsphinx import AudioFile\n\n# Frames per Second\nfps = 100\n\nfor phrase in AudioFile(frate=fps):  # frate (default=100)\n    print('-' * 28)\n    print('| %5s |  %3s  |   %4s   |' % ('start', 'end', 'word'))\n    print('-' * 28)\n    for s in phrase.seg():\n        print('| %4ss | %4ss | %8s |' % (s.start_frame / fps, s.end_frame / fps, s.word))\n    print('-' * 28)\n\n# ----------------------------\n# | start |  end  |   word   |\n# ----------------------------\n# |  0.0s | 0.24s | \u003cs\u003e      |\n# | 0.25s | 0.45s | \u003csil\u003e    |\n# | 0.46s | 0.63s | go       |\n# | 0.64s | 1.16s | forward  |\n# | 1.17s | 1.52s | ten      |\n# | 1.53s | 2.11s | meters   |\n# | 2.12s |  2.6s | \u003c/s\u003e     |\n# ----------------------------\n```\n\n### Pocketsphinx\n\nIt's a simple and flexible proxy class to `pocketsphinx.Decode`.\n\n```python\nfrom pocketsphinx import Pocketsphinx\nprint(Pocketsphinx().decode()) # =\u003e \"go forward ten meters\"\n```\n\nA more comprehensive example:\n\n```python\nfrom __future__ import print_function\nimport os\nfrom pocketsphinx import Pocketsphinx, get_model_path, get_data_path\n\nmodel_path = get_model_path()\ndata_path = get_data_path()\n\nconfig = {\n    'hmm': os.path.join(model_path, 'en-us'),\n    'lm': os.path.join(model_path, 'en-us.lm.bin'),\n    'dict': os.path.join(model_path, 'cmudict-en-us.dict')\n}\n\nps = Pocketsphinx(**config)\nps.decode(\n    audio_file=os.path.join(data_path, 'goforward.raw'),\n    buffer_size=2048,\n    no_search=False,\n    full_utt=False\n)\n\nprint(ps.segments()) # =\u003e ['\u003cs\u003e', '\u003csil\u003e', 'go', 'forward', 'ten', 'meters', '\u003c/s\u003e']\nprint('Detailed segments:', *ps.segments(detailed=True), sep='\\n') # =\u003e [\n#     word, prob, start_frame, end_frame\n#     ('\u003cs\u003e', 0, 0, 24)\n#     ('\u003csil\u003e', -3778, 25, 45)\n#     ('go', -27, 46, 63)\n#     ('forward', -38, 64, 116)\n#     ('ten', -14105, 117, 152)\n#     ('meters', -2152, 153, 211)\n#     ('\u003c/s\u003e', 0, 212, 260)\n# ]\n\nprint(ps.hypothesis())  # =\u003e go forward ten meters\nprint(ps.probability()) # =\u003e -32079\nprint(ps.score())       # =\u003e -7066\nprint(ps.confidence())  # =\u003e 0.04042641466841839\n\nprint(*ps.best(count=10), sep='\\n') # =\u003e [\n#     ('go forward ten meters', -28034)\n#     ('go for word ten meters', -28570)\n#     ('go forward and majors', -28670)\n#     ('go forward and meters', -28681)\n#     ('go forward and readers', -28685)\n#     ('go forward ten readers', -28688)\n#     ('go forward ten leaders', -28695)\n#     ('go forward can meters', -28695)\n#     ('go forward and leaders', -28706)\n#     ('go for work ten meters', -28722)\n# ]\n```\n\n### Default config\n\nIf you don't pass any argument while creating an instance of the Pocketsphinx, AudioFile or LiveSpeech class, it will use next default values:\n\n```python\nverbose = False\nlogfn = /dev/null or nul\naudio_file = site-packages/pocketsphinx/data/goforward.raw\naudio_device = None\nsampling_rate = 16000\nbuffer_size = 2048\nno_search = False\nfull_utt = False\nhmm = site-packages/pocketsphinx/model/en-us\nlm = site-packages/pocketsphinx/model/en-us.lm.bin\ndict = site-packages/pocketsphinx/model/cmudict-en-us.dict\n```\n\nAny other option must be passed into the config as is, without using symbol `-`.\n\nIf you want to disable default language model or dictionary, you can change the value of the corresponding options to False:\n\n```python\nlm = False\ndict = False\n```\n\n### Verbose\n\nSend output to stdout:\n\n```python\nfrom pocketsphinx import Pocketsphinx\n\nps = Pocketsphinx(verbose=True)\nps.decode()\n\nprint(ps.hypothesis())\n```\n\nSend output to file:\n\n```python\nfrom pocketsphinx import Pocketsphinx\n\nps = Pocketsphinx(verbose=True, logfn='pocketsphinx.log')\nps.decode()\n\nprint(ps.hypothesis())\n```\n\n### Compatibility\n\nParent classes are still available:\n\n```python\nimport os\nfrom pocketsphinx import DefaultConfig, Decoder, get_model_path, get_data_path\n\nmodel_path = get_model_path()\ndata_path = get_data_path()\n\n# Create a decoder with a certain model\nconfig = DefaultConfig()\nconfig.set_string('-hmm', os.path.join(model_path, 'en-us'))\nconfig.set_string('-lm', os.path.join(model_path, 'en-us.lm.bin'))\nconfig.set_string('-dict', os.path.join(model_path, 'cmudict-en-us.dict'))\ndecoder = Decoder(config)\n\n# Decode streaming data\nbuf = bytearray(1024)\nwith open(os.path.join(data_path, 'goforward.raw'), 'rb') as f:\n    decoder.start_utt()\n    while f.readinto(buf):\n        decoder.process_raw(buf, False, False)\n    decoder.end_utt()\nprint('Best hypothesis segments:', [seg.word for seg in decoder.seg()])\n```\n\n## Install development version\n\n### Install requirements\n\nWindows requirements:\n\n* [Python](https://www.python.org/downloads)\n* [Git](http://git-scm.com/downloads)\n* [Swig](http://www.swig.org/download.html)\n* [Visual Studio Community](https://www.visualstudio.com/ru-ru/downloads/download-visual-studio-vs.aspx)\n\nUbuntu requirements:\n\n```shell\nsudo apt-get install -qq python python-dev python-pip build-essential swig git libpulse-dev libasound2-dev\n```\n\nMac OS X requirements:\n\n```shell\nbrew reinstall swig python\n```\n\n### Install with pip\n\n```shell\npip install https://github.com/bambocher/pocketsphinx-python/archive/master.zip\n```\n\n### Install with distutils\n\n```shell\ngit clone --recursive https://github.com/bambocher/pocketsphinx-python\ncd pocketsphinx-python\npython setup.py install\n```\n\n## Projects using pocketsphinx-python\n\n* [SpeechRecognition](https://github.com/Uberi/speech_recognition) - Library for performing speech recognition, with support for several engines and APIs, online and offline.\n\n## License\n\n[The BSD License](https://github.com/bambocher/pocketsphinx-python/blob/master/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbambocher%2Fpocketsphinx-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbambocher%2Fpocketsphinx-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbambocher%2Fpocketsphinx-python/lists"}