0

I am trying to set up PocketSphinx for a Python application that will hopefully use speech recognition. I would like to use PocketSphinx to do this; however, its installation is causing me a lot of issues.

Here is the script I am trying to run:

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

try:
    print("Sphinx hears... " +r.recognize_sphinx(audio))
except sr.UnknownValueError:
    print("ERROR")

I am using Windows 10, Python 3.6.1, and I've used pip for all of my installs (except swig).

The first big issue comes with setting up swig. I have followed other SO questions and answers, which have finally led me to download this http://prdownloads.sourceforge.net/swig/swigwin-3.0.12.zip. After extracting this into my Python site-packages library, issues still persist.

The reason I am trying to use swig in th eifrst place is because of PocketSphinx. When using pip install pocketsphinx I receive this error message:

Complete output from command

c:\users\jacob\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;file='C:\Users\Jacob\AppData\Local\Temp\pip-build-29fk_pde\pocketsphinx\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\Jacob\AppData\Local\Temp\pip-b395jwge-record\install-record.txt --single-version-externally-managed --compile:

running install running build_ext building 'sphinxbase._ad' extension swigging swig/sphinxbase/ad.i to swig/sphinxbase/ad_wrap.c swig.exe -python -modern -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/win32 -Ideps/sphinxbase/swig -outdir sphinxbase -o swig/sphinxbase/ad_wrap.c swig/sphinxbase/ad.i error: command 'swig.exe' failed: No such file or directory

----------------------------------------

Command "c:\users\jacob\appdata\local\programs\python\python36-32\python.exe -u >-c "import setuptools, tokenize;file='C:\Users\Jacob\AppData\Local\Temp\pip-build-29fk_pde\pocketsphinx\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\Jacob\AppData\Local\Temp\pip-b395jwge-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Jacob\AppData\Local\Temp\pip-build-29fk_pde\pocketsphinx\

Since this didn't work, I ended up trying to alternatively download https://gigenet.dl.sourceforge.net/project/cmusphinx/pocketsphinx/5prealpha/pocketsphinx-5prealpha-win32.zip , as suggested in another SO answer.

After placing that file into my Python's site packages again, there still seems to be an error when trying to run my Python code which requires the PocketSphinx:

Traceback (most recent call last):
  File "C:\Users\Jacob\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 651, in recognize_sphinx
    from pocketsphinx import pocketsphinx
ModuleNotFoundError: No module named 'pocketsphinx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Jacob/Desktop/python programs/listener.py", line 9, in <module>
    print("Sphinx hears... " +r.recognize_sphinx(audio))
  File "C:\Users\Jacob\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 653, in recognize_sphinx
    raise RequestError("missing PocketSphinx module: ensure that PocketSphinx is set up correctly.")
speech_recognition.RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.

It would be greatly appreciated if someone could help me navigate through these installations or point me in the right direction. So that I may get my final code running.

Jacob A
  • 109
  • 1
  • 10
  • Possible duplicate of [Swig not found when installing pocketsphinx Python](https://stackoverflow.com/questions/33745389/swig-not-found-when-installing-pocketsphinx-python) – Nikolay Shmyrev Aug 15 '17 at 17:05
  • @Nikolat Shmyrev I have tried installing visual C++ on multiple devices to no avail. I was hoping there'd be an alternative solution – Jacob A Aug 16 '17 at 14:43
  • From my understanding, a C or C++ compiler is not necessary to use swig, only to compile it. On the other hand, I have the same problem when using a precompiled swig.exe. – Ingo Schalk-Schupp Nov 24 '17 at 12:25

0 Answers0