pax_global_header00006660000000000000000000000064133050566450014521gustar00rootroot0000000000000052 comment=769492da47e41b71e3dd57a6b033fbba79e57032 pocketsphinx-python-0.1.15/000077500000000000000000000000001330505664500156435ustar00rootroot00000000000000pocketsphinx-python-0.1.15/.gitignore000066400000000000000000000004421330505664500176330ustar00rootroot00000000000000.idea/ .vscode/ build/ dist/ MANIFEST __pycache__ *.pyd *.egg-info *.so *.htk *.lat *.pyc *.log sphinxbase/ad_win32.py sphinxbase/ad_openal.py sphinxbase/ad_pulse.py sphinxbase/ad_alsa.py sphinxbase/sphinxbase.py pocketsphinx/pocketsphinx.py *_wrap.c pocketsphinx/data/ pocketsphinx/model/ pocketsphinx-python-0.1.15/.gitmodules000066400000000000000000000003201330505664500200130ustar00rootroot00000000000000[submodule "deps/pocketsphinx"] path = deps/pocketsphinx url = https://github.com/cmusphinx/pocketsphinx [submodule "deps/sphinxbase"] path = deps/sphinxbase url = https://github.com/cmusphinx/sphinxbase pocketsphinx-python-0.1.15/.travis.yml000066400000000000000000000053531330505664500177620ustar00rootroot00000000000000sudo: false env: global: secure: kRjum2tZsaQZPnti27bc/ZIjYS1hftXTyuSWdq/6raRignORgbZMUc/RMXBz+ig8kiEVE3SFBZdapECGj+3Vb6Q6Vi4ypv8lR4rtJMTNITSOeM1KHHDCi6xLLGKrOsJ5ndkYHTNxuyIMGZu9Sv3TMcNqHcBChbZKT383OXgrxLA= matrix: include: - os: osx osx_image: xcode6.4 language: generic env: ENABLE_LIBSPHINXAD=1 BUILD_WHEEL=true - os: osx osx_image: xcode8 language: generic env: ENABLE_LIBSPHINXAD=1 BUILD_WHEEL=true - os: osx osx_image: xcode8.3 language: generic env: ENABLE_LIBSPHINXAD=1 BUILD_WHEEL=true - os: osx osx_image: xcode9.3 language: generic env: ENABLE_LIBSPHINXAD=1 BUILD_WHEEL=true - os: linux language: python python: 2.7 env: ENABLE_LIBSPHINXAD=1 - os: linux language: python python: 3.5 env: ENABLE_LIBSPHINXAD=1 - os: linux language: python python: 3.6 env: ENABLE_LIBSPHINXAD=1 BUILD_SDIST=true before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew reinstall swig python python@2; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH=$HOME/Library/Python/3.6/bin:$PATH; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y swig libpulse-dev libasound2-dev; fi install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then python2 -m pip install --user --upgrade pip setuptools wheel twine; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then python3 -m pip install --user --upgrade pip setuptools wheel twine; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then python -m pip install --upgrade pip setuptools wheel twine; fi script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then python2 setup.py test; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then python3 setup.py test; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then python setup.py test; fi before_deploy: - if [[ "$TRAVIS_OS_NAME" == "osx" && "$BUILD_SDIST" == "true" ]]; then python2 setup.py sdist; fi - if [[ "$TRAVIS_OS_NAME" == "osx" && "$BUILD_WHEEL" == "true" ]]; then python2 setup.py bdist_wheel; fi - if [[ "$TRAVIS_OS_NAME" == "osx" && "$BUILD_SDIST" == "true" ]]; then python3 setup.py sdist; fi - if [[ "$TRAVIS_OS_NAME" == "osx" && "$BUILD_WHEEL" == "true" ]]; then python3 setup.py bdist_wheel; fi - if [[ "$TRAVIS_OS_NAME" == "linux" && "$BUILD_SDIST" == "true" ]]; then python setup.py sdist; fi - if [[ "$TRAVIS_OS_NAME" == "linux" && "$BUILD_WHEEL" == "true" ]]; then python setup.py bdist_wheel; fi deploy: provider: script script: twine upload -u bambucha -p $PASSWORD dist/* on: tags: true branch: master condition: '"$BUILD_SDIST" == "true" || "$BUILD_WHEEL" == "true"' skip_cleanup: true pocketsphinx-python-0.1.15/LICENSE000066400000000000000000000027751330505664500166630ustar00rootroot00000000000000Copyright (c) 1999-2016 Carnegie Mellon University. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. This work was supported in part by funding from the Defense Advanced Research Projects Agency and the National Science Foundation of the United States of America, and the CMU Sphinx Speech Consortium. THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.pocketsphinx-python-0.1.15/MANIFEST.in000066400000000000000000000006211330505664500174000ustar00rootroot00000000000000recursive-include deps/sphinxbase/include *.h prune deps/sphinxbase/include/wince recursive-include deps/sphinxbase/src/libsphinxad *.c recursive-include deps/sphinxbase/src/libsphinxbase *.c *.h recursive-include deps/pocketsphinx/include *.h recursive-include deps/pocketsphinx/src/libpocketsphinx *.c *.h global-include *.i graft pocketsphinx/model graft pocketsphinx/data include README.md LICENSEpocketsphinx-python-0.1.15/README.md000066400000000000000000000216631330505664500171320ustar00rootroot00000000000000# Pocketsphinx Python [![Latest Version](https://img.shields.io/pypi/v/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx) [![Development Status](https://img.shields.io/pypi/status/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx) [![Supported Python Versions](https://img.shields.io/pypi/pyversions/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx) [![Travis Build Status](https://travis-ci.org/bambocher/pocketsphinx-python.svg?branch=master)](https://travis-ci.org/bambocher/pocketsphinx-python) [![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) [![License](https://img.shields.io/pypi/l/pocketsphinx.svg?maxAge=86400)](https://pypi.org/project/pocketsphinx) Pocketsphinx is a part of the [CMU Sphinx](http://cmusphinx.sourceforge.net) Open Source Toolkit For Speech Recognition. This 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). ## Supported platforms * Windows * Linux * Mac OS X ## Installation ```shell # Make sure we have up-to-date versions of pip, setuptools and wheel python -m pip install --upgrade pip setuptools wheel pip install --upgrade pocketsphinx ``` More binary distributions for manual installation are available [here](https://pypi.org/project/pocketsphinx/#files). ## Usage ### LiveSpeech It's an iterator class for continuous recognition or keyword search from a microphone. ```python from pocketsphinx import LiveSpeech for phrase in LiveSpeech(): print(phrase) ``` An example of a keyword search: ```python from pocketsphinx import LiveSpeech speech = LiveSpeech(lm=False, keyphrase='forward', kws_threshold=1e-20) for phrase in speech: print(phrase.segments(detailed=True)) ``` With your model and dictionary: ```python import os from pocketsphinx import LiveSpeech, get_model_path model_path = get_model_path() speech = LiveSpeech( verbose=False, sampling_rate=16000, buffer_size=2048, no_search=False, full_utt=False, hmm=os.path.join(model_path, 'en-us'), lm=os.path.join(model_path, 'en-us.lm.bin'), dic=os.path.join(model_path, 'cmudict-en-us.dict') ) for phrase in speech: print(phrase) ``` ### AudioFile It's an iterator class for continuous recognition or keyword search from a file. ```python from pocketsphinx import AudioFile for phrase in AudioFile(): print(phrase) # => "go forward ten meters" ``` An example of a keyword search: ```python from pocketsphinx import AudioFile audio = AudioFile(lm=False, keyphrase='forward', kws_threshold=1e-20) for phrase in audio: print(phrase.segments(detailed=True)) # => "[('forward', -617, 63, 121)]" ``` With your model and dictionary: ```python import os from pocketsphinx import AudioFile, get_model_path, get_data_path model_path = get_model_path() data_path = get_data_path() config = { 'verbose': False, 'audio_file': os.path.join(data_path, 'goforward.raw'), 'buffer_size': 2048, 'no_search': False, 'full_utt': False, 'hmm': os.path.join(model_path, 'en-us'), 'lm': os.path.join(model_path, 'en-us.lm.bin'), 'dict': os.path.join(model_path, 'cmudict-en-us.dict') } audio = AudioFile(**config) for phrase in audio: print(phrase) ``` Convert frame into time coordinates: ```python from pocketsphinx import AudioFile # Frames per Second fps = 100 for phrase in AudioFile(frate=fps): # frate (default=100) print('-' * 28) print('| %5s | %3s | %4s |' % ('start', 'end', 'word')) print('-' * 28) for s in phrase.seg(): print('| %4ss | %4ss | %8s |' % (s.start_frame / fps, s.end_frame / fps, s.word)) print('-' * 28) # ---------------------------- # | start | end | word | # ---------------------------- # | 0.0s | 0.24s | | # | 0.25s | 0.45s | | # | 0.46s | 0.63s | go | # | 0.64s | 1.16s | forward | # | 1.17s | 1.52s | ten | # | 1.53s | 2.11s | meters | # | 2.12s | 2.6s | | # ---------------------------- ``` ### Pocketsphinx It's a simple and flexible proxy class to `pocketsphinx.Decode`. ```python from pocketsphinx import Pocketsphinx print(Pocketsphinx().decode()) # => "go forward ten meters" ``` A more comprehensive example: ```python from __future__ import print_function import os from pocketsphinx import Pocketsphinx, get_model_path, get_data_path model_path = get_model_path() data_path = get_data_path() config = { 'hmm': os.path.join(model_path, 'en-us'), 'lm': os.path.join(model_path, 'en-us.lm.bin'), 'dict': os.path.join(model_path, 'cmudict-en-us.dict') } ps = Pocketsphinx(**config) ps.decode( audio_file=os.path.join(data_path, 'goforward.raw'), buffer_size=2048, no_search=False, full_utt=False ) print(ps.segments()) # => ['', '', 'go', 'forward', 'ten', 'meters', ''] print('Detailed segments:', *ps.segments(detailed=True), sep='\n') # => [ # word, prob, start_frame, end_frame # ('', 0, 0, 24) # ('', -3778, 25, 45) # ('go', -27, 46, 63) # ('forward', -38, 64, 116) # ('ten', -14105, 117, 152) # ('meters', -2152, 153, 211) # ('', 0, 212, 260) # ] print(ps.hypothesis()) # => go forward ten meters print(ps.probability()) # => -32079 print(ps.score()) # => -7066 print(ps.confidence()) # => 0.04042641466841839 print(*ps.best(count=10), sep='\n') # => [ # ('go forward ten meters', -28034) # ('go for word ten meters', -28570) # ('go forward and majors', -28670) # ('go forward and meters', -28681) # ('go forward and readers', -28685) # ('go forward ten readers', -28688) # ('go forward ten leaders', -28695) # ('go forward can meters', -28695) # ('go forward and leaders', -28706) # ('go for work ten meters', -28722) # ] ``` ### Default config If you don't pass any argument while creating an instance of the Pocketsphinx, AudioFile or LiveSpeech class, it will use next default values: ```python verbose = False logfn = /dev/null or nul audio_file = site-packages/pocketsphinx/data/goforward.raw audio_device = None sampling_rate = 16000 buffer_size = 2048 no_search = False full_utt = False hmm = site-packages/pocketsphinx/model/en-us lm = site-packages/pocketsphinx/model/en-us.lm.bin dict = site-packages/pocketsphinx/model/cmudict-en-us.dict ``` Any other option must be passed into the config as is, without using symbol `-`. If you want to disable default language model or dictionary, you can change the value of the corresponding options to False: ```python lm = False dict = False ``` ### Verbose Send output to stdout: ```python from pocketsphinx import Pocketsphinx ps = Pocketsphinx(verbose=True) ps.decode() print(ps.hypothesis()) ``` Send output to file: ```python from pocketsphinx import Pocketsphinx ps = Pocketsphinx(verbose=True, logfn='pocketsphinx.log') ps.decode() print(ps.hypothesis()) ``` ### Compatibility Parent classes are still available: ```python import os from pocketsphinx import DefaultConfig, Decoder, get_model_path, get_data_path model_path = get_model_path() data_path = get_data_path() # Create a decoder with a certain model config = DefaultConfig() config.set_string('-hmm', os.path.join(model_path, 'en-us')) config.set_string('-lm', os.path.join(model_path, 'en-us.lm.bin')) config.set_string('-dict', os.path.join(model_path, 'cmudict-en-us.dict')) decoder = Decoder(config) # Decode streaming data buf = bytearray(1024) with open(os.path.join(data_path, 'goforward.raw'), 'rb') as f: decoder.start_utt() while f.readinto(buf): decoder.process_raw(buf, False, False) decoder.end_utt() print('Best hypothesis segments:', [seg.word for seg in decoder.seg()]) ``` ## Install development version ### Install requirements Windows requirements: * [Python](https://www.python.org/downloads) * [Git](http://git-scm.com/downloads) * [Swig](http://www.swig.org/download.html) * [Visual Studio Community](https://www.visualstudio.com/ru-ru/downloads/download-visual-studio-vs.aspx) Ubuntu requirements: ```shell sudo apt-get install -qq python python-dev python-pip build-essential swig git libpulse-dev libasound2-dev ``` Mac OS X requirements: ```shell brew reinstall swig python ``` ### Install with pip ```shell pip install https://github.com/bambocher/pocketsphinx-python/archive/master.zip ``` ### Install with distutils ```shell git clone --recursive https://github.com/bambocher/pocketsphinx-python cd pocketsphinx-python python setup.py install ``` ## Projects using pocketsphinx-python * [SpeechRecognition](https://github.com/Uberi/speech_recognition) - Library for performing speech recognition, with support for several engines and APIs, online and offline. ## License [The BSD License](https://github.com/bambocher/pocketsphinx-python/blob/master/LICENSE) pocketsphinx-python-0.1.15/appveyor.yml000066400000000000000000000014361330505664500202370ustar00rootroot00000000000000version: 0.1.15 ({build}) environment: PASSWORD: secure: KZdEfjKCVSUL334LJP/iPqWKfzhoIm43D4VZwJcEb0k= matrix: - PYTHON: C:\Python27 - PYTHON: C:\Python35 - PYTHON: C:\Python36 - PYTHON: C:\Python27-x64 - PYTHON: C:\Python35-x64 - PYTHON: C:\Python36-x64 init: - set VS90COMNTOOLS=%VS140COMNTOOLS% - set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH% install: - git submodule update --init --recursive - choco install -y swig --allow-empty-checksums - python -m pip install --upgrade pip setuptools wheel twine build: off test_script: - python setup.py test after_test: - python setup.py bdist_wheel - python setup.py bdist_wininst artifacts: - path: dist/* on_success: - if %APPVEYOR_REPO_TAG%==true twine upload -u bambucha -p %PASSWORD% dist/* pocketsphinx-python-0.1.15/deps/000077500000000000000000000000001330505664500165765ustar00rootroot00000000000000pocketsphinx-python-0.1.15/deps/pocketsphinx/000077500000000000000000000000001330505664500213155ustar00rootroot00000000000000pocketsphinx-python-0.1.15/deps/sphinxbase/000077500000000000000000000000001330505664500207425ustar00rootroot00000000000000pocketsphinx-python-0.1.15/pocketsphinx/000077500000000000000000000000001330505664500203625ustar00rootroot00000000000000pocketsphinx-python-0.1.15/pocketsphinx/__init__.py000066400000000000000000000165631330505664500225060ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os import sys import signal from contextlib import contextmanager from sphinxbase import * from .pocketsphinx import * DefaultConfig = Decoder.default_config def get_model_path(): """ Return path to the model. """ return os.path.join(os.path.dirname(__file__), 'model') def get_data_path(): """ Return path to the data. """ return os.path.join(os.path.dirname(__file__), 'data') class Pocketsphinx(Decoder): def __init__(self, **kwargs): model_path = get_model_path() data_path = get_data_path() self.goforward = os.path.join(data_path, 'goforward.raw') if kwargs.get('dic') is not None and kwargs.get('dict') is None: kwargs['dict'] = kwargs.pop('dic') if kwargs.get('hmm') is None: kwargs['hmm'] = os.path.join(model_path, 'en-us') if kwargs.get('lm') is None: kwargs['lm'] = os.path.join(model_path, 'en-us.lm.bin') if kwargs.get('dict') is None: kwargs['dict'] = os.path.join(model_path, 'cmudict-en-us.dict') if kwargs.pop('verbose', False) is False: if sys.platform.startswith('win'): kwargs['logfn'] = 'nul' else: kwargs['logfn'] = '/dev/null' config = DefaultConfig() for key, value in kwargs.items(): if isinstance(value, bool): config.set_boolean('-{}'.format(key), value) elif isinstance(value, int): config.set_int('-{}'.format(key), value) elif isinstance(value, float): config.set_float('-{}'.format(key), value) elif isinstance(value, str): config.set_string('-{}'.format(key), value) super(Pocketsphinx, self).__init__(config) def __str__(self): return self.hypothesis() @contextmanager def start_utterance(self): self.start_utt() yield self.end_utt() @contextmanager def end_utterance(self): self.end_utt() yield self.start_utt() def decode(self, audio_file=None, buffer_size=2048, no_search=False, full_utt=False): buf = bytearray(buffer_size) with open(audio_file or self.goforward, 'rb') as f: with self.start_utterance(): while f.readinto(buf): self.process_raw(buf, no_search, full_utt) return self def segments(self, detailed=False): if detailed: return [ (s.word, s.prob, s.start_frame, s.end_frame) for s in self.seg() ] else: return [s.word for s in self.seg()] def hypothesis(self): hyp = self.hyp() if hyp: return hyp.hypstr else: return '' def probability(self): hyp = self.hyp() if hyp: return hyp.prob def score(self): hyp = self.hyp() if hyp: return hyp.best_score def best(self, count=10): return [ (h.hypstr, h.score) for h, i in zip(self.nbest(), range(count)) ] def confidence(self): hyp = self.hyp() if hyp: return self.get_logmath().exp(hyp.prob) class AudioFile(Pocketsphinx): def __init__(self, **kwargs): signal.signal(signal.SIGINT, self.stop) self.audio_file = kwargs.pop('audio_file', None) self.buffer_size = kwargs.pop('buffer_size', 2048) self.no_search = kwargs.pop('no_search', False) self.full_utt = kwargs.pop('full_utt', False) self.keyphrase = kwargs.get('keyphrase') self.in_speech = False self.buf = bytearray(self.buffer_size) super(AudioFile, self).__init__(**kwargs) self.f = open(self.audio_file or self.goforward, 'rb') def __iter__(self): with self.f: with self.start_utterance(): while self.f.readinto(self.buf): self.process_raw(self.buf, self.no_search, self.full_utt) if self.keyphrase and self.hyp(): with self.end_utterance(): yield self elif self.in_speech != self.get_in_speech(): self.in_speech = self.get_in_speech() if not self.in_speech and self.hyp(): with self.end_utterance(): yield self def stop(self, *args, **kwargs): raise StopIteration class LiveSpeech(Pocketsphinx): def __init__(self, **kwargs): signal.signal(signal.SIGINT, self.stop) self.audio_device = kwargs.pop('audio_device', None) self.sampling_rate = kwargs.pop('sampling_rate', 16000) self.buffer_size = kwargs.pop('buffer_size', 2048) self.no_search = kwargs.pop('no_search', False) self.full_utt = kwargs.pop('full_utt', False) self.keyphrase = kwargs.get('keyphrase') self.in_speech = False self.buf = bytearray(self.buffer_size) self.ad = Ad(self.audio_device, self.sampling_rate) super(LiveSpeech, self).__init__(**kwargs) def __iter__(self): with self.ad: with self.start_utterance(): while self.ad.readinto(self.buf) >= 0: self.process_raw(self.buf, self.no_search, self.full_utt) if self.keyphrase and self.hyp(): with self.end_utterance(): yield self elif self.in_speech != self.get_in_speech(): self.in_speech = self.get_in_speech() if not self.in_speech and self.hyp(): with self.end_utterance(): yield self def stop(self, *args, **kwargs): raise StopIteration pocketsphinx-python-0.1.15/setup.cfg000066400000000000000000000000251330505664500174610ustar00rootroot00000000000000[build_ext] inplace=1pocketsphinx-python-0.1.15/setup.py000066400000000000000000000231711330505664500173610ustar00rootroot00000000000000#!/usr/bin/env python import os import sys from shutil import copy, copytree, ignore_patterns from glob import glob from distutils import log from distutils.command.build import build as _build try: from setuptools import setup, Extension from setuptools.command.install import install as _install from setuptools.command.bdist_egg import bdist_egg as _bdist_egg except ImportError: from distutils.core import setup from distutils.extension import Extension from distutils.command.install import install as _install from distutils.command.bdist_egg import bdist_egg as _bdist_egg if sys.platform.startswith('win'): from distutils.command.bdist_msi import bdist_msi as _bdist_msi from distutils.command.bdist_wininst import bdist_wininst as _bdist_wininst def _find_vcvarsall(version): vsbase = msvc9compiler.VS_BASE % version productdir = None if version != 9.0: try: productdir = msvc9compiler.Reg.get_value(r"%s\Setup\VC" % vsbase, "productdir") except KeyError: log.debug("Unable to find productdir in registry") if not productdir or not os.path.isdir(productdir): toolskey = "VS%0.f0COMNTOOLS" % version toolsdir = os.environ.get(toolskey, None) if toolsdir and os.path.isdir(toolsdir): productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.abspath(productdir) if not os.path.isdir(productdir): log.debug("%s is not a valid directory" % productdir) return None else: log.debug("Env var %s is not set or invalid" % toolskey) if not productdir: log.debug("No productdir found") return None vcvarsall = os.path.join(productdir, "vcvarsall.bat") if os.path.isfile(vcvarsall): return vcvarsall log.debug("Unable to find vcvarsall.bat") return None try: from distutils import msvc9compiler msvc9compiler.find_vcvarsall = _find_vcvarsall except ImportError: pass extra_compile_args = [] extra_link_args = [] libsphinxbase = ( glob('deps/sphinxbase/src/libsphinxbase/lm/*.c') + glob('deps/sphinxbase/src/libsphinxbase/feat/*.c') + glob('deps/sphinxbase/src/libsphinxbase/util/*.c') + glob('deps/sphinxbase/src/libsphinxbase/fe/*.c') ) libpocketsphinx = glob('deps/pocketsphinx/src/libpocketsphinx/*.c') sb_sources = ( libsphinxbase + ['deps/sphinxbase/swig/sphinxbase.i'] ) ps_sources = ( libsphinxbase + libpocketsphinx + ['deps/pocketsphinx/swig/pocketsphinx.i'] ) sb_include_dirs = [ 'deps/sphinxbase/include', 'deps/sphinxbase/include/sphinxbase' ] ps_include_dirs = ['deps/pocketsphinx/include'] define_macros = [ ('SPHINXBASE_EXPORTS', None), ('POCKETSPHINX_EXPORTS', None), ('SPHINX_DLL', None), ('HAVE_CONFIG_H', None) ] if sys.platform.startswith('win'): sb_include_dirs.append('deps/sphinxbase/include/win32') extra_compile_args.extend([ '/wd4244', '/wd4267', '/wd4197', '/wd4090', '/wd4018', '/wd4311', '/wd4312', '/wd4334', '/wd4477', '/wd4996' ]) extra_link_args.append('/ignore:4197') elif sys.platform.startswith('darwin'): sb_include_dirs.append('deps/sphinxbase/include/android') extra_compile_args.extend([ '-Wno-macro-redefined', '-Wno-sign-compare', '-Wno-logical-op-parentheses' ]) elif sys.platform.startswith('linux'): sb_include_dirs.append('deps/sphinxbase/include/android') extra_compile_args.extend([ '-Wno-unused-label', '-Wno-strict-prototypes', '-Wno-parentheses', '-Wno-unused-but-set-variable', '-Wno-unused-variable', '-Wno-unused-result', '-Wno-sign-compare', '-Wno-misleading-indentation' ]) sb_swig_opts = ( ['-modern', '-threads'] + ['-I' + h for h in sb_include_dirs] + ['-Ideps/sphinxbase/swig'] + ['-outdir', 'sphinxbase'] ) ps_swig_opts = ( ['-modern', '-threads'] + ['-I' + h for h in sb_include_dirs + ps_include_dirs] + ['-Ideps/sphinxbase/swig'] + ['-outdir', 'pocketsphinx'] ) if not os.path.exists(os.path.join(os.path.dirname(__file__), 'pocketsphinx/model')): copytree(os.path.join(os.path.dirname(__file__), 'deps/pocketsphinx/model/en-us'), os.path.join(os.path.dirname(__file__), 'pocketsphinx/model'), ignore=ignore_patterns('en-us-phone.lm.bin')) if not os.path.exists(os.path.join(os.path.dirname(__file__), 'pocketsphinx/data')): os.makedirs(os.path.join(os.path.dirname(__file__), 'pocketsphinx/data')) copy(os.path.join(os.path.dirname(__file__), 'deps/pocketsphinx/test/data/goforward.raw'), os.path.join(os.path.dirname(__file__), 'pocketsphinx/data/goforward.raw')) class build(_build): def run(self): self.run_command('build_ext') return _build.run(self) class install(_install): def run(self): self.run_command('build_ext') return _install.run(self) cmdclass = { 'build': build, 'install': install, } try: from wheel.bdist_wheel import bdist_wheel as _bdist_wheel except ImportError: pass else: class bdist_wheel(_bdist_wheel): def run(self): self.run_command('build_ext') return _bdist_wheel.run(self) cmdclass['bdist_wheel'] = bdist_wheel if sys.platform.startswith('win'): class bdist_wininst(_bdist_wininst): def run(self): self.run_command('build_ext') return _bdist_wininst.run(self) cmdclass['bdist_wininst'] = bdist_wininst ext_modules = [ Extension( name='sphinxbase._sphinxbase', sources=sb_sources, swig_opts=sb_swig_opts, include_dirs=sb_include_dirs, define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ), Extension( name='pocketsphinx._pocketsphinx', sources=ps_sources, swig_opts=ps_swig_opts, include_dirs=sb_include_dirs + ps_include_dirs, define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ) ] if sys.platform.startswith('win'): ext_modules.append( Extension( name='sphinxbase._ad_win32', sources=['swig/sphinxbase/ad_win32.i', 'deps/sphinxbase/src/libsphinxad/ad_win32.c'], swig_opts=sb_swig_opts, include_dirs=sb_include_dirs, libraries=['winmm'], define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ) ) elif sys.platform.startswith('darwin'): sb_include_dirs.append('/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers') ext_modules.append( Extension( name='sphinxbase._ad_openal', sources=['swig/sphinxbase/ad_openal.i', 'deps/sphinxbase/src/libsphinxad/ad_openal.c'], swig_opts=sb_swig_opts, include_dirs=sb_include_dirs, extra_objects=['/System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL'], define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ) ) elif sys.platform.startswith('linux'): ext_modules.extend([ Extension( name='sphinxbase._ad_pulse', sources=['swig/sphinxbase/ad_pulse.i', 'deps/sphinxbase/src/libsphinxad/ad_pulse.c'], swig_opts=sb_swig_opts, include_dirs=sb_include_dirs, libraries=['pulse', 'pulse-simple'], define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ), Extension( name='sphinxbase._ad_alsa', sources=['swig/sphinxbase/ad_alsa.i', 'deps/sphinxbase/src/libsphinxad/ad_alsa.c'], swig_opts=sb_swig_opts, include_dirs=sb_include_dirs, libraries=['asound'], define_macros=define_macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args ) ]) setup( name='pocketsphinx', version='0.1.15', description='Python interface to CMU Sphinxbase and Pocketsphinx libraries', long_description=open('README.md').read(), long_description_content_type='text/markdown', author='Dmitry Prazdnichnov', author_email='dmitry@prazdnichnov.name', maintainer='Dmitry Prazdnichnov', maintainer_email='dmitry@prazdnichnov.name', url='https://github.com/bambocher/pocketsphinx-python', download_url='https://pypi.org/project/pocketsphinx/#files', packages=['sphinxbase', 'pocketsphinx'], ext_modules=ext_modules, cmdclass=cmdclass, classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX :: Linux', 'Operating System :: MacOS', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: C', 'Intended Audience :: Developers', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Multimedia :: Sound/Audio :: Speech' ], license='BSD', keywords='sphinxbase pocketsphinx', test_suite='tests', include_package_data=True, zip_safe=False ) pocketsphinx-python-0.1.15/sphinxbase/000077500000000000000000000000001330505664500200075ustar00rootroot00000000000000pocketsphinx-python-0.1.15/sphinxbase/__init__.py000066400000000000000000000035221330505664500221220ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys if sys.platform.startswith('win'): from .ad_win32 import * elif sys.platform.startswith('darwin'): from .ad_openal import * elif sys.platform.startswith('linux'): try: from .ad_pulse import * except: from .ad_alsa import * from .sphinxbase import * pocketsphinx-python-0.1.15/swig/000077500000000000000000000000001330505664500166145ustar00rootroot00000000000000pocketsphinx-python-0.1.15/swig/sphinxbase/000077500000000000000000000000001330505664500207605ustar00rootroot00000000000000pocketsphinx-python-0.1.15/swig/sphinxbase/ad_alsa.i000066400000000000000000000050411330505664500225160ustar00rootroot00000000000000/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* ==================================================================== * Copyright (c) 2013 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * */ %define DOCSTRING "This documentation was automatically generated using original comments in Doxygen format. As some C types and data structures cannot be directly mapped into Python types, some non-trivial type conversion could have place. Basically a type is replaced with another one that has the closest match, and sometimes one argument of generated function comprises several arguments of the original function (usually two). Functions having error code as the return value and returning effective value in one of its arguments are transformed so that the effective value is returned in a regular fashion and run-time exception is being thrown in case of negative error code." %enddef %module(docstring=DOCSTRING) ad_alsa %feature("autodoc", "1"); %include ad_base.i pocketsphinx-python-0.1.15/swig/sphinxbase/ad_base.i000066400000000000000000000056611330505664500225200ustar00rootroot00000000000000/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* ==================================================================== * Copyright (c) 2013 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * */ %include pybuffer.i %include typemaps.i %{ #include typedef ad_rec_t Ad; %} typedef struct {} Ad; %extend Ad { Ad(const char *audio_device=NULL, int sampling_rate=16000, int *errcode) { Ad *ad; if (audio_device == NULL) ad = ad_open_sps(sampling_rate); else ad = ad_open_dev(audio_device, sampling_rate); *errcode = ad ? 0 : -1; return ad; } ~Ad() { ad_close($self); } Ad *__enter__(int *errcode) { *errcode = ad_start_rec($self); return $self; } void __exit__(PyObject *exception_type, PyObject *exception_value, PyObject *exception_traceback, int *errcode) { *errcode = ad_stop_rec($self); } int start_recording(int *errcode) { return *errcode = ad_start_rec($self); } int stop_recording(int *errcode) { return *errcode = ad_stop_rec($self); } %include %pybuffer_mutable_binary(char *DATA, size_t SIZE); int readinto(char *DATA, size_t SIZE, int *errcode) { return *errcode = ad_read($self, (int16*)DATA, SIZE /= sizeof(int16)); } } pocketsphinx-python-0.1.15/swig/sphinxbase/ad_openal.i000066400000000000000000000050431330505664500230560ustar00rootroot00000000000000/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* ==================================================================== * Copyright (c) 2013 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * */ %define DOCSTRING "This documentation was automatically generated using original comments in Doxygen format. As some C types and data structures cannot be directly mapped into Python types, some non-trivial type conversion could have place. Basically a type is replaced with another one that has the closest match, and sometimes one argument of generated function comprises several arguments of the original function (usually two). Functions having error code as the return value and returning effective value in one of its arguments are transformed so that the effective value is returned in a regular fashion and run-time exception is being thrown in case of negative error code." %enddef %module(docstring=DOCSTRING) ad_openal %feature("autodoc", "1"); %include ad_base.i pocketsphinx-python-0.1.15/swig/sphinxbase/ad_pulse.i000066400000000000000000000050421330505664500227270ustar00rootroot00000000000000/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* ==================================================================== * Copyright (c) 2013 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * */ %define DOCSTRING "This documentation was automatically generated using original comments in Doxygen format. As some C types and data structures cannot be directly mapped into Python types, some non-trivial type conversion could have place. Basically a type is replaced with another one that has the closest match, and sometimes one argument of generated function comprises several arguments of the original function (usually two). Functions having error code as the return value and returning effective value in one of its arguments are transformed so that the effective value is returned in a regular fashion and run-time exception is being thrown in case of negative error code." %enddef %module(docstring=DOCSTRING) ad_pulse %feature("autodoc", "1"); %include ad_base.i pocketsphinx-python-0.1.15/swig/sphinxbase/ad_win32.i000066400000000000000000000050421330505664500225410ustar00rootroot00000000000000/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* ==================================================================== * Copyright (c) 2013 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * */ %define DOCSTRING "This documentation was automatically generated using original comments in Doxygen format. As some C types and data structures cannot be directly mapped into Python types, some non-trivial type conversion could have place. Basically a type is replaced with another one that has the closest match, and sometimes one argument of generated function comprises several arguments of the original function (usually two). Functions having error code as the return value and returning effective value in one of its arguments are transformed so that the effective value is returned in a regular fashion and run-time exception is being thrown in case of negative error code." %enddef %module(docstring=DOCSTRING) ad_win32 %feature("autodoc", "1"); %include ad_base.i pocketsphinx-python-0.1.15/tests/000077500000000000000000000000001330505664500170055ustar00rootroot00000000000000pocketsphinx-python-0.1.15/tests/__init__.py000066400000000000000000000030531330505664500211170ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pocketsphinx-python-0.1.15/tests/test_audiofile.py000066400000000000000000000035121330505664500223600ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import AudioFile class TestAudioFile(TestCase): def test_audiofile(self): hypothesis = '' for phrase in AudioFile(): hypothesis = str(phrase) self.assertEqual(hypothesis, 'go forward ten meters') pocketsphinx-python-0.1.15/tests/test_config.py000066400000000000000000000056021330505664500216660ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import DefaultConfig class TestConfig(TestCase): def test_config_get_float(self): config = DefaultConfig() self.assertEqual(config.get_float('-samprate'), 16000.0) def test_config_set_float(self): config = DefaultConfig() config.set_float('-samprate', 8000.0) self.assertEqual(config.get_float('-samprate'), 8000.0) def test_config_get_int(self): config = DefaultConfig() self.assertEqual(config.get_int('-nfft'), 512) def test_config_set_int(self): config = DefaultConfig() config.set_int('-nfft', 256) self.assertEqual(config.get_int('-nfft'), 256) def test_config_get_string(self): config = DefaultConfig() self.assertEqual(config.get_string('-rawlogdir'), None) def test_config_set_string(self): config = DefaultConfig() config.set_string('-rawlogdir', '~/pocketsphinx') self.assertEqual(config.get_string('-rawlogdir'), '~/pocketsphinx') def test_config_get_boolean(self): config = DefaultConfig() self.assertEqual(config.get_boolean('-backtrace'), False) def test_config_set_boolean(self): config = DefaultConfig() config.set_boolean('-backtrace', True) self.assertEqual(config.get_boolean('-backtrace'), True) pocketsphinx-python-0.1.15/tests/test_decoder.py000066400000000000000000000066431330505664500220340ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import Pocketsphinx class TestRawDecoder(TestCase): def __init__(self, *args, **kwargs): self.ps = Pocketsphinx() self.ps.decode() super(TestRawDecoder, self).__init__(*args, **kwargs) def test_raw_decoder_lookup_word(self): self.assertEqual(self.ps.lookup_word('hello'), 'HH AH L OW') self.assertEqual(self.ps.lookup_word('abcdf'), None) def test_raw_decoder_hypothesis(self): self.assertEqual(self.ps.hypothesis(), 'go forward ten meters') self.assertEqual(self.ps.score(), -7066) self.assertEqual(self.ps.confidence(), 0.04042641466841839) def test_raw_decoder_segments(self): self.assertEqual(self.ps.segments(), [ '', '', 'go', 'forward', 'ten', 'meters', '' ]) def test_raw_decoder_best_hypothesis(self): self.assertEqual(self.ps.best(), [ ('go forward ten meters', -28034), ('go for word ten meters', -28570), ('go forward and majors', -28670), ('go forward and meters', -28681), ('go forward and readers', -28685), ('go forward ten readers', -28688), ('go forward ten leaders', -28695), ('go forward can meters', -28695), ('go forward and leaders', -28706), ('go for work ten meters', -28722) ]) class TestCepDecoder(TestCase): def test_cep_decoder_hypothesis(self): ps = Pocketsphinx() with open('deps/pocketsphinx/test/data/goforward.mfc', 'rb') as f: with ps.start_utterance(): f.read(4) buf = f.read(13780) ps.process_cep(buf, False, True) self.assertEqual(ps.hypothesis(), 'go forward ten meters') self.assertEqual(ps.score(), -7095) self.assertEqual(ps.probability(), -32715) pocketsphinx-python-0.1.15/tests/test_fsg.py000066400000000000000000000040401330505664500211730ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import LogMath, FsgModel class TestFsg(TestCase): def test_fsg_word_add(self): fm = FsgModel('simple_grammar', LogMath(), 1.0, 10) fm.word_add('hello') fm.word_add('world') self.assertGreaterEqual(fm.word_id('world'), 0) def test_fsg_add_silence(self): fm = FsgModel('simple_grammar', LogMath(), 1.0, 10) fm.add_silence('', 1, 0.5) self.assertGreaterEqual(fm.word_id(''), 0) pocketsphinx-python-0.1.15/tests/test_jsgf.py000066400000000000000000000045471330505664500213610ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import Pocketsphinx, Jsgf class TestJsgf(TestCase): def test_jsgf(self): ps = Pocketsphinx( lm='deps/pocketsphinx/test/data/turtle.lm.bin', dic='deps/pocketsphinx/test/data/turtle.dic' ) # Decoding with 'turtle' language model ps.decode() self.assertEqual(ps.hypothesis(), 'go forward ten meters') # Switch to JSGF grammar jsgf = Jsgf('deps/pocketsphinx/test/data/goforward.gram') rule = jsgf.get_rule('goforward.move2') fsg = jsgf.build_fsg(rule, ps.get_logmath(), 7.5) ps.set_fsg('goforward', fsg) ps.set_search('goforward') # Decoding with 'goforward' grammar ps.decode() self.assertEqual(ps.hypothesis(), 'go forward ten meters') pocketsphinx-python-0.1.15/tests/test_kws.py000066400000000000000000000036421330505664500212270ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import AudioFile class TestKws(TestCase): def test_kws(self): segments = [] for phrase in AudioFile(lm=False, keyphrase='forward', kws_threshold=1e+20): segments = phrase.segments(detailed=True) self.assertEqual(segments, [('forward', -617, 63, 121)]) pocketsphinx-python-0.1.15/tests/test_lattice.py000066400000000000000000000036611330505664500220510ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import Pocketsphinx class TestLattice(TestCase): def test_lattice(self): ps = Pocketsphinx() ps.decode() lattice = ps.get_lattice() self.assertEqual(lattice.write('tests/goforward.lat'), None) lattice = ps.get_lattice() self.assertEqual(lattice.write_htk('tests/goforward.htk'), None) pocketsphinx-python-0.1.15/tests/test_lm.py000066400000000000000000000051061330505664500210300ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import Pocketsphinx, NGramModel class TestLm(TestCase): def test_lm(self): ps = Pocketsphinx( dic='deps/pocketsphinx/test/data/defective.dic', mmap=False ) # Decoding with 'defective' dictionary ps.decode() self.assertEqual(ps.hypothesis(), '') # Switch to 'turtle' language model turtle_lm = 'deps/pocketsphinx/test/data/turtle.lm.bin' lm = NGramModel(ps.get_config(), ps.get_logmath(), turtle_lm) ps.set_lm('turtle', lm) ps.set_search('turtle') # Decoding with 'turtle' language model ps.decode() self.assertEqual(ps.hypothesis(), '') # The word 'meters' isn't in the loaded dictionary # Let's add it manually ps.add_word('foobie', 'F UW B IY', False) ps.add_word('meters', 'M IY T ER Z', True) # Decoding with 'turtle' language model ps.decode() self.assertEqual(ps.hypothesis(), 'foobie meters meters') pocketsphinx-python-0.1.15/tests/test_phoneme.py000066400000000000000000000051041330505664500220510ustar00rootroot00000000000000# Copyright (c) 1999-2016 Carnegie Mellon University. All rights # reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # This work was supported in part by funding from the Defense Advanced # Research Projects Agency and the National Science Foundation of the # United States of America, and the CMU Sphinx Speech Consortium. # # THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY # NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from unittest import TestCase from pocketsphinx import Pocketsphinx class TestPhoneme(TestCase): def __init__(self, *args, **kwargs): self.ps = Pocketsphinx( lm=False, dic=False, allphone='deps/pocketsphinx/model/en-us/en-us-phone.lm.bin', lw=2.0, pip=0.3, beam=1e-200, pbeam=1e-20, mmap=False ) self.ps.decode() super(TestPhoneme, self).__init__(*args, **kwargs) def test_phoneme_hypothesis(self): self.assertEqual( self.ps.hypothesis(), 'SIL G OW F AO R D T AE N NG IY ZH ER S SIL' ) def test_phoneme_best_phonemes(self): self.assertEqual(self.ps.segments(), [ 'SIL', 'G', 'OW', 'F', 'AO', 'R', 'D', 'T', 'AE', 'N', 'NG', 'IY', 'ZH', 'ER', 'S', 'SIL' ])