php-docs-samples/speech/api at master · rastabrane/php-docs-samples · GitHub
Skip to content

Latest commit

 

History

History
 
 

Folders and files

README.md

Google Cloud Speech API Samples

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 Google Cloud 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/api
$ composer install

Configure your project using Application Default Credentials

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

Audio Format

For the best results, use SoX to format audio files into raw format:

sox YourAudio.mp3 --rate 16k -encoding signed -bits 8 YourAudio.raw

See Choosing an Audio Encoding for more information.

Usage

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

php speech.php transcribe YourAudio.raw --encoding LINEAR16 --sample-rate 16000