Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Google Cloud Speech to Custom Search Demo

This sample shows you how to use the Google Cloud Speech API to transcribe live audio from your computer's microphone and transmit it to a custom search API or web browser.

Prerequisites

Enable the Speech API

If you have not already done so, enable the Google Cloud Speech API for your project.

Setup the Custom Search API

Setup a Custom Search API and make note of the value in the URL that comes after cx=, this is the identifier you will need when configuring the sample.

Authentication

This sample uses a service accounts for authentication to the Speech API.

  • Visit the Cloud Console, and navigate to:

    API Manager > Credentials > Create credentials > Service account key > New service account.

  • Create a new service account, and download the json credentials file.

  • Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to your downloaded service account credentials:

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json
    

    If you do not do this, the streaming sample will just sort of hang silently.

You also must generate a developer API key that will be used with the Custom Search Engine.

See the Cloud Platform Auth Guide for more information.

Setup

  • Clone this repo

    git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
    cd python-docs-samples/speech/grpc
  • If you don't have it already, install virtualenv.

    pip install virtualenv
  • Create a virtualenv. This isolates the python dependencies you're about to install, to minimize conflicts with any existing libraries you might already have.

    virtualenv env
    source env/bin/activate
  • Install PortAudio. The sample uses the PyAudio library to stream audio from your computer's microphone. PyAudio depends on PortAudio for cross-platform compatibility, and is installed differently depending on the platform. For example:

    • For Mac OS X, you can use Homebrew:

      brew install portaudio
    • For Debian / Ubuntu Linux:

      apt-get install portaudio19-dev python-all-dev
    • Windows may work without having to install PortAudio explicitly (it will get installed with PyAudio, when you run python -m pip install ... below).

    • For more details, see the PyAudio installation page.

  • Install the python dependencies:

    pip install -r requirements.txt
  • Replace the values for API_KEY and CSE_ID in speech_to_search.py with those from the Google Cloud Developer Console and Custom Search Engine you created previously.

Troubleshooting

PortAudio on OS X

If you see the error

fatal error: 'portaudio.h' file not found

Try adding the following to your ~/.pydistutils.cfg file, substituting in your appropriate brew Cellar directory:

include_dirs=/usr/local/Cellar/portaudio/19.20140130/include/
library_dirs=/usr/local/$USER/homebrew/Cellar/portaudio/19.20140130/lib/

Run the sample

  • To run the speech_to_search.py sample:

    python speech_to_search.py

To demo the sample:

  • Speak to transcribe what you say and send it to your Custom Search Engine. The sample will speak back the first result.
  • Say "next" to read the next result.
  • Say "quit" or "exit" to quit the sample.

Deactivate virtualenv

When you're done running the sample, you can exit your virtualenv:

deactivate