How to install "Libraries: SpeechRecognition, pyttsx3, & PyAudio of Python" ????

I will also demonstrate how to import modules pyttsx3, SpeechRecognition in this post along with PyAudio as mentioned in the title. 

Firstly, ensure that python is installed by running the below command from the cmd prompt.

py -3 --version                                                                                                    

Installation of module pyttsx3

Go to MS Visual Studio Code and open the terminal(powershell) to install module pyttsx3. 


Later, I tried to install the package in another folder where I created a python project.  

Once installed, use the below command to verify if it is installed. 

pip list                                                                                 

Installation of ipykernel 

While running the program, I also installed ipykernel as it was showing up some new error. 

A powerful interactive Python shell and a Jupyter kernel to work with Python code in Jupyter notebooks and other interactive frontends.

Setting Up Environment variable as Python 3.9.1

I also got another error 'ModuleNotFoundError' while running.


The above problem could be the incorrect global environment variables. Once I choose Python 3.9.1 32-bit, it started working. Because the installed version of Python 3.9.1. 

Installation of SpeechRecognition

Once I made text to speech work, I started with speech to text.  


Installation of pyaudio

Installing pyaudio has some problem with pip commands, so I installed Anaconda individual edition to install the pyaudio with conda.


Installation of pyaudio using conda (Not Worked)

Though I installed Anaconda individual edition (from https://www.anaconda.com/products/individual), I couldn't install PyAudio. Later, I checked if the conda is installed in Windows by executing the below command in the cmd prompt. 



So, I added the conda path to the system environment variables as depicted in the screenshot below. 
Windows->View Advanced System Settings->  System Settings-> Advanced -> Environment Variables -> Path-> Edit (Edit Environment variables) ->New 




Dont'forget to add C:\Users\<username>\Anaconda3\Library\bin to your path variable otherwise you will get a SSL error if this performed on a fresh install of Anaconda. 




Now, close and re-open the MS Visual Studio Code and run 'conda install PyAudio' in Powershell terminal. 




Neverthless, installing pyaudio using conda didn't help much because I got the below error while running the program. So again I checked the running python version in command prompt. 



PIP & Python version 

There might be a chance the pip can run on another python version which is not the version you will get while running Python. 

python -V                                                    
py -V                                                           
pip -V                                                          

To see which versions are (correctly) installed on your system, run the below
py -0p                                                 >>>>>>>> It is is -'zero'p and not alphabet o        




This clearly tells the pyaudio which is installed in anaconda has different python version (3.8.32), but the current python program runs on 3.9.



So, I planned to use pip instead of conda. So I tried the following commands, it worked. 

Installation of pyaudio using pip (Worked)


pip install pipwin                                                                                  
pipwin install pyaudio                                                                           

PS E:\Mini_project\Speech_asst>  pip install pipwin
Collecting pipwin
  Downloading pipwin-0.5.1.tar.gz (8.8 kB)
Collecting docopt
  Downloading docopt-0.6.2.tar.gz (25 kB)
Collecting requests
  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 215 kB/s
Collecting pyprind
  Downloading PyPrind-2.11.3-py2.py3-none-any.whl (8.4 kB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting beautifulsoup4>=4.9.0
  Downloading beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)
     |████████████████████████████████| 115 kB 726 kB/s
Collecting js2py
  Downloading Js2Py-0.71-py3-none-any.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 437 kB/s
Collecting packaging
  Downloading packaging-20.9-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 325 kB/s
Collecting pySmartDL>=1.3.1
  Downloading pySmartDL-1.3.4-py3-none-any.whl (20 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.4-py2.py3-none-any.whl (153 kB)
     |████████████████████████████████| 153 kB 939 kB/s
Collecting certifi>=2017.4.17
  Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 731 kB/s
Collecting idna<3,>=2.5
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 490 kB/s
Collecting chardet<5,>=3.0.2
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     |████████████████████████████████| 178 kB 1.1 MB/s
Collecting soupsieve>1.2; python_version >= "3.0"
  Downloading soupsieve-2.2.1-py3-none-any.whl (33 kB)
Collecting tzlocal>=1.2
  Downloading tzlocal-2.1-py2.py3-none-any.whl (16 kB)
Collecting pyjsparser>=2.5.1
  Downloading pyjsparser-2.7.1.tar.gz (24 kB)
Collecting pyparsing>=2.0.2
  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
     |████████████████████████████████| 67 kB 554 kB/s
Collecting pytz
  Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
     |████████████████████████████████| 510 kB 312 kB/s
Building wheels for collected packages: pipwin, docopt, pyjsparser
  Building wheel for pipwin (setup.py) ... done
  Created wheel for pipwin: filename=pipwin-0.5.1-py2.py3-none-any.whl size=8778 sha256=4aaf92ba5a0db65437114eb0816852464ebfc3d976e7db2cafc3ca41037572ce
  Stored in directory: c:\users\hai\appdata\local\pip\cache\wheels\ee\cc\6a\8ea3d6061d20d2ce4d82c27382afb240ae0c24a52a05d7ea64
  Building wheel for docopt (setup.py) ... done
  Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13705 sha256=3e12894263113dfc17882b03d5cbd72aca65be05ce2d91724ff9bcf8ae2a3fa4
  Stored in directory: c:\users\hai\appdata\local\pip\cache\wheels\70\4a\46\1309fc853b8d395e60bafaf1b6df7845bdd82c95fd59dd8d2b
  Building wheel for pyjsparser (setup.py) ... done
  Created wheel for pyjsparser: filename=pyjsparser-2.7.1-py3-none-any.whl size=25998 sha256=b40f3a40a4837ff4b87e6783ee77aff7741242c14cbfaac048473b913ca2d37c
  Stored in directory: c:\users\hai\appdata\local\pip\cache\wheels\f0\70\61\f42dc45dcf0fbe8c495ce579b04730787081499bfb5b8bc60e
Successfully built pipwin docopt pyjsparser
pySmartDL, pipwin
Successfully installed beautifulsoup4-4.9.3 certifi-2020.12.5 chardet-4.0.0 docopt-0.6.2 idna-2.10 js2py-0.71 packaging-20.9 pipwin-0.5.1 pySmartDL-1.3.4 pyjsparser-2.7.1 pyparsing-2.4.7 pyprind-2.11.3 pytz-2021.1 requests-2.25.1 six-1.15.0 soupsieve-2.2.1 tzlocal-2.1 urllib3-1.26.4
WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.
You should consider upgrading via the 'c:\python\python.exe -m pip install --upgrade pip' command.
PS E:\Mini_project\Speech_asst>
PS E:\Mini_project\Speech_asst>
PS E:\Mini_project\Speech_asst>
PS E:\Mini_project\Speech_asst> pipwin install pyaudio
Building cache. Hang on . . .
Done
Package `pyaudio` found in cache
Downloading package . . .
https://download.lfd.uci.edu/pythonlibs/w4tscw6k/PyAudio-0.2.11-cp39-cp39-win32.whl
PyAudio-0.2.11-cp39-cp39-win32.whl
 [*] 94 kB / 94 kB @ 36 kB/s [##################] [100%, 0s left]
Processing c:\users\hai\pipwin\pyaudio-0.2.11-cp39-cp39-win32.whl
Successfully installed PyAudio-0.2.11
WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.
You should consider upgrading via the 'c:\python\python.exe -m pip install --upgrade pip' command.
PS E:\Mini_project\Speech_asst>

Uninstallation of Anaconda Individual Edition 

Later, I uninstalled Anaconda software as it wasn't used for pyaudio. 

Fixing Microphone issue 

At this point, microphone was not working, and it was only just listening but speech wasn't converted to text. Click here to see the code. The error was 'return pa.read.stream(self._stream, num_frames, exception_on_overflow)'




July - My Speech Assistant

So, I carefully looked into the microphone settings, and since bluetooth headphone wasn't chosen as input device, my voice wasn't audible. After the correction, 'July' (My Voice Assistant Name) was able to hear me. I felt bad that it couldn't hear my name(Shirley was converted to surely here) properly :-( 



References 

Stackoverflow 
EduYear - Youtube channel




Comments