Skip to main content

Python module for speech recognition using Google speech recognition API

Project description

Google Speech To Text for Python

Python module for speech recognition using Google’s speech recognition API.</br> Tested in ubuntu 13.10 with python_2.7


For LINUX - Please install the sox and simplejson with the following lines in your terminal:

sudo  apt-get install sox

sudo  pip install simplejson

For OSX you need to install Homebrew first and then the dependencies (PIP already comes with python so you might want to test in your terminal to verify your version) otherwise if you haven’t installed python yet please do with “sudo brew install python” as shown in the following lines:

sudo ruby -e "$(curl -fsSL"

sudo brew install sox

sudo brew install python

sudo pip install simplejson


gosttPy module recieves a voice command from the user (through the microphone) and executes a google search… It achieves this by recording a .flac audio file and uploading it to google’s speech recognition engine which converts it into readable text. The output from google is a JSON object with a list of posible interpretations/transcripts (translations from voice to text. A google speech API KEY will be needed for the module to work. Please get one from the google developers wesite:

The JSON object looks like this:

{“result”:[{“alternative”:[{“transcript”:”world”,”confidence”:0.43871391}, {“transcript”:”World”},{“transcript”:”solo”},{“transcript”:”solo world”},{“transcript”:”so wharo”}],”final”:true}],”result_index”:0}

The result of this operation becomes a google search engine query that outputs some result related to the original voice command…

The goosttPy module allows you to choose between different outputs:

  1. ‘RAW’ –> Google’s speech API JSON object (Complete / not-parsed)raw-data

  2. ‘FIRST’ –> Just the first transcripted version of your voice

  3. ‘ALL’ –> The list of all the transcripts returned by the google speech API

  4. ‘SEARCH’ –> includes the search result returned from google

Example / Usage

python code:

from gosttpy import gosttpy # From the file import the class goosttPy

speech = gosttpy.gosttpy()

# Google API key for voice recognition (Replace the string 'YOUR-GOOGLE-SPEECH-API-KEY' with
#your google API Key. Follow this link:

#returnType --> options are: 'RAW', 'FIRST', 'ALL', 'SEARCH'
returnType = 'FIRST'
returnedText = speech.voiceRecognitionAndSearch(apiKey, returnType)
print returnedText

Project details

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page