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.
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
For the best results, use SoX to format audio files into raw format:
sox YourAudio.mp3 --rate 16k -encoding signed -bits 8 YourAudio.rawSee Choosing an Audio Encoding for more information.
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