Skip to content

Files

Failed to load latest commit information.

Latest commit

 Cannot retrieve latest commit at this time.

History

History

speech

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Speech API Samples

Open in Cloud Shell

These samples show how to use the Google Cloud Speech API to transcribe audio files, as well as live audio from your computer's microphone.

This repository contains samples that use the Cloud Speech Client Library for PHP to make REST calls as well as contains samples using the more-efficient (though sometimes more complex) GRPC API. The GRPC API also allows streaming requests.

Installation

Install the dependencies for this library via composer

$ cd /path/to/php-docs-samples/speech
$ composer install

Configure your project using Application Default Credentials

$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json

Usage

Run php src/SNIPPET_NAME.php. The usage will print for each if no arguments are provided:

$ php src/transcribe_sync.php
Usage: php src/transcribe_sync.php AUDIO_FILE

$ php src/transcribe_sync.php test/data/audio32KHz.raw
Transcript: how old is the Brooklyn Bridge
Confidence: 0.98662775754929

Once you have a speech sample in the proper format, send it through the speech API using the transcribe command:

php src/transcribe_sync.php test/data/audio32KHz.raw
php src/transcribe_async.php test/data/audio32KHz.raw
php src/transcribe_async_words.php test/data/audio32KHz.raw

Troubleshooting

If you get the following error, set the environment variable GCLOUD_PROJECT to your project ID:

[Google\Cloud\Core\Exception\GoogleException]
No project ID was provided, and we were unable to detect a default project ID.

If you have not set a timezone you may get an error from php. This can be resolved by:

  1. Finding where the php.ini is stored by running php -i | grep 'Configuration File'
  2. Finding out your timezone from the list on this page: http://php.net/manual/en/timezones.php
  3. Editing the php.ini file (or creating one if it doesn't exist)
  4. Adding the timezone to the php.ini file e.g., adding the following line: date.timezone = "America/Los_Angeles"