{"id":13741520,"url":"https://github.com/cmusphinx/pocketsphinx-python","last_synced_at":"2025-05-08T21:34:10.115Z","repository":{"id":24688183,"uuid":"28099282","full_name":"cmusphinx/pocketsphinx-python","owner":"cmusphinx","description":"Python module installed with setup.py","archived":true,"fork":true,"pushed_at":"2022-06-29T15:22:48.000Z","size":25654,"stargazers_count":338,"open_issues_count":0,"forks_count":81,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-08-03T04:08:11.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bambocher/pocketsphinx-python","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmusphinx.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}},"created_at":"2014-12-16T18:01:33.000Z","updated_at":"2024-02-25T21:01:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cmusphinx/pocketsphinx-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fpocketsphinx-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fpocketsphinx-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fpocketsphinx-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fpocketsphinx-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmusphinx","download_url":"https://codeload.github.com/cmusphinx/pocketsphinx-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224774861,"owners_count":17367808,"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":[],"created_at":"2024-08-03T04:00:59.923Z","updated_at":"2024-11-15T11:31:24.058Z","avatar_url":"https://github.com/cmusphinx.png","language":"Python","readme":"# Pocketsphinx Python\n\n**This module is no longer relevant, and is being archived. Python bindings are included in the [pocketsphinx](https://github.com/cmusphinx/pocketsphinx) module. Alternatively, you may consider using [bambocher/pocketsphinx-python](https://github.com/bambocher/pocketsphinx-python)**\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```\ngit clone --recursive https://github.com/cmusphinx/pocketsphinx-python/\ncd pocketsphinx-python\npython setup.py install\n```\n\n## Usage\n\n### LiveSpeech\n\nAn iterator class for continuous recognition or keyword search from a microphone.\nNote that this is not supported (yet) in macOS Big Sur.\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\nAn 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 UPSTREAM version with pip\n\nNote that this is NOT the same as this version under github cmusphinx.\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/cmusphinx/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":["Software","Python"],"sub_categories":["Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2Fpocketsphinx-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmusphinx%2Fpocketsphinx-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2Fpocketsphinx-python/lists"}