Speech recognition with python

Posted by Carlos Ganoza on 23 Mar, 2014

Well, after such a long time without writing I decided to migrate my blog to this subdomain and change blogger for hexo in github (I promise to talk about hexo in another post, if you can’t stand the curiosity, google it).

Now what it touches; There are some tools in python for speech recognition, such as an implementation of CMU Sphinx that works very well for English, or others that use the Dragon Naturally Speaking api that therefore only works on Windows.
Some time ago I programmed a small python library that uses google api to recognize speech, its name is Pygsr and its use is very simple:
We only install it:

  • sox - apt-get install sox
  • pyaudio - apt-get install python-pyaudio

how to use it:

example.py
1
2
3
4
5
6

from pygsr import Pygsr
speech = Pygsr()
speech.record(3) # duration in seconds (3)
phrase, complete_response = speech.speech_to_text('es_ES') # select the language
print phrase

As you will see its use is very easy you just have to set the time you will be listening, select the language and after processing the speech will return the string with the text.

  • PD: pygsr works very well in linux, but not in mac, why ?, I do not know, I have not had the opportunity to try it in one but many people have reported to me that there is an error with pyAudio, library that I use to work pygsr; I promise to check it out soon.
  • PD2: when using pygsr using google api will only work with an internet connection, this could be a limitation.
    Link: https://github.com/drneox/pygsr

UPDATE

Apparently Google no longer allows the free use of your api, if you want to use it you must pay.
For this reason I will no longer keep this library.
If you want to integrate voice recognition into your project I recommend taking a look at the wit.ai project.
https://wit.ai


Carlos Ganoza

I have more than 6 years of experience in the technology market, I have been involved in different aspects of software development, cybersecurity, and open-source. I ♥ python, the open-source, and I always enjoy learning new skills.