Skip to content

Latest commit

 

History

History
 
 

README.md

Google Cloud Speech REST API Samples

These samples show how to use the Google Cloud Speech API to transcribe audio files, using the REST-based Google API Client Library for Python.

For samples that use the more-efficient GRPC-based client library (including a streaming sample that transcribes audio streamed from your microphone), see ../grpc/.

Prerequisites

Enable the Speech API

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

Authentication

These samples use service accounts for authentication.

  • 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 REST api will return a 403.

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/api-client
  • 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 the dependencies

    pip install -r requirements.txt

Run the sample

Each of the samples takes the audio file to transcribe as the first argument. For example:

python transcribe.py resources/audio.raw

You should see a response with the transcription result.

Deactivate virtualenv

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

deactivate