TPocketSphinx

The required minimum set of pocketsphinx (and sphinxbase) headers, translated to Object Pascal. Custom thread wrapper TPocketSphinx is capable of recognizing English speech live from a default audio source in Windows and Linux, call back with status and hypothesis if available.

PocketSphinx is a lightweight speech recognition engine, specifically tuned for handheld and mobile devices, though it works equally well on the desktop

Building examples

  1. Demos: colors and anyword were designed in Lazarus (version 1.6.0 used). Demo anyword-delphi was tested in Delphi XE10.
  2. Linux only: pocketsphinx installation is explained in this tutorial. Basically ./configure and make install for sphinxbase and pocketsphinx (in this order).
  3. Build any of the examples:
    examples\colors\PocketSphinxColors.lpi - Recognition of few words defined in grammar and dictionary files: black, blue, green, red, yellow, white. This demo will initialize very quickly and use minimum resources, since dictionary file contains only few words and search scope is limited to them.
    examples\anyword\PocketSphinxAnyWord.lpi - Recognition of any word from a US English dictionary (~135k words), in Ngram language model search mode.
    examples\anyword-delphi\PocketSphinxDelphi.dproj - Above demo but for Delphi

    If building in Lazarus for Linux, change build configuration respectively (Windows configuration is default).
  4. Download and unpack latest pocketsphinx (pocketsphinx-5prealpha-win32.zip originally used). Copy files:
    - all files and subdirectories pocketsphinx\model\en-us to bin\en-us
    Windows:
    - pocketsphinx\bin\Release\Win32\pocketsphinx.dll to bin\pocketsphinx.dll
    - pocketsphinx\bin\Release\Win32\sphinxbase.dll to bin\sphinxbase.dll
  5. Make sure your recording device is set to microphone in system, since examples make use of default audio device.
  6. Execute built demo and speak. If PocketSphinx fails to initialize - rebuild demo with Debug configuration, ps.log file is created with full log.
    In Windows if you get an error: "missing MSVCR110D.DLL", try installing Microsoft Visual C++ 2012 Redistributable in your system.

Creating new grammar

Colors demo explains how to limit acceptable words via JSpeech Grammar Format file bin\colors\colors.gram

To create a new list of "accepted" words that can be used in your "command and control" type of application:

  • Define words in grammar file, accordingly to your set of rules (words combine, repetitions etc.)
  • Create dictionary file with all of those words, and their pronunciation with tools listed below
  • Load dictionary and add new search with LoadDictionary and AddGrammarSearchFile 
Multiple words to pronunciation (.dic) file Single word to pronunciation
LOGIOS Lexicon Tool The CMU Pronouncing Dictionary
http://www.speech.cs.cmu.edu/tools/lextool.html http://www.speech.cs.cmu.edu/cgi-bin/cmudict

Make sure that words in your dictionary and grammar file are lowercase or uppercase for both (not mixed), otherwise PocketSphinx will fail to initialize.

Download

https://github.com/cmusphinx/pocketsphinx/archive/master.zip

License

MIT (refer to LICENSE.md file)

Version history

r5 (19.12.2016)
Fix for missing AudioSource property

r3 (13.09.2016)
Example usage with BASS audio library

r2 (20.05.2016)
Linux support
Delphi demo
Modular audio source

r1 (10.05.2016)
Initial version

 

    Comments

    Submitted bytrenatos on Tue, 17/05/2016 - 12:03

    I try to follow the directions but I get this error when I try to run either file: The application was unable to start correctly (0xc000007b). Click OK to close the application.

    I'm on Windows 7, using Lazarus 1.6

    What happens if you start the demo executable outside the debugger ? Does it say about missing msvcr1xx.dll ? Visual C++ Redistributable is required for PocketSphinx DLLs to run correctly, as far as i remember that is 2012 version.

    Progress, when I use the x64 DLLs instead, the programs start.

    When closing, I get an error report though.

    The accuracy is low but I'm entirely sure that's a microphone issue, as I'm using a built-in (Same result as when I tested Sphinx with Java), will test with a proper mic later on.

    Thanks a whole bunch man, I've been looking forever for a good voice solution for Lazarus.

    If both Lazarus and OS is x64 then demo projects will compile for Win64 platform instead of Win32, that's why you had to use x64 DLLs, my bad. I will correct build modes in next release - with Linux support, and changes in how audio source and search methods (key phrase / N-gram / JSGF / all phone N-gram) are selected. I've been also looking forever for a speech recognition engine in Pascal that does not depend on SAPI and is preferably completely free - so i'm glad i was able to help you too :-)

    Submitted bytrenatos on Wed, 18/05/2016 - 00:05

    I'm trying to modify the colors example, but as soon as I try to add a word, I get "Failed to initialize decoder".

    I've tried generating new dictionary and grammar file, and just adding a word to the existing example, any idea what would be wrong?

    --edit

    It seems that when I try to modify things, the log always complains about the last word in the dictionary not existing

    --edit
    Figured it out, mismatched case between .dic and .gram file, one was capitalized, all working now!

    Submitted byocsp on Mon, 31/07/2017 - 16:21

    Hi dear friend
    i was happy when i found your blog and i was reading your post until finally i found no link to your work !
    as i can see the only download link is about pocketsphinx original github page !
    What's the matter ? should we pay for this pascal headers or some thing is wrong about me ?!
    please tell me know ...
    Thanks in advance