These samples demonstrate how to call the Google Cloud Speech API using C++.
These samples will only build and run on Linux.
-
Create a project in the Google Cloud Platform Console. If you haven't already created a project, create one now. Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.
- Open the Cloud Platform Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.
-
Enable billing for your project. If you haven't already enabled billing for your project, enable billing now. Enabling billing allows the application to consume billable resources such as Speech API calls. See Cloud Platform Console Help for more information about billing settings.
-
Enable APIs for your project. Click here to visit Cloud Platform Console and enable the Speech API.
-
Download service account credentials. These samples use service accounts for authentication.
- Visit the Cloud Console, and navigate to:
API Manager > Credentials > Create credentials > Service account key - Under Service account, select
New service account. - Under Service account name, enter a service account name of your choosing. For example,
transcriber. - Under Role, select
Project > Owner. - Under Key type, leave
JSONselected. - Click Create to create a new service account, and download the json credentials file.
- Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to point to your downloaded service account credentials:export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json
See the Cloud Platform Auth Guide for more information.
- Visit the Cloud Console, and navigate to:
-
Install vcpkg. This project uses
vcpkgfor dependency management. Clone the vcpkg repository to your preferred location. In these instructions we use$HOME:git clone -C $HOME https://github.com/microsoft/vcpkg.git -
Download or clone this repo with
git clone https://github.com/GoogleCloudPlatform/cpp-samples
-
Compile these examples: Use the
vcpkgtoolchain file to download and compile dependencies. This file would be in the directory you clonedvcpkginto,$HOME/vcpkgif you are following the instructions to the letter. Note that building all the dependencies can take up to an hour, depending on the performance of your workstation. These dependencies are cached, so a second build should be substantially faster.cd cpp-samples/speech/api cmake -S. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build
-
Run the examples:
.build/transcribe -b 16000 resources/audio.raw .build/transcribe --bitrate 16000 resources/audio2.raw .build/transcribe resources/audio.flac .build/transcribe resources/quit.raw .build/streaming_transcribe -b 16000 resources/audio.raw .build/streaming_transcribe --bitrate 16000 resources/audio2.raw .build/streaming_transcribe resources/audio.flac .build/streaming_transcribe resources/quit.raw .build/streaming_transcribe_singlethread -b 16000 resources/audio.raw .build/streaming_transcribe_singlethread --bitrate 16000 resources/audio2.raw .build/streaming_transcribe_singlethread resources/audio.flac .build/streaming_transcribe_singlethread resources/quit.raw .build/transcribe gs://cloud-samples-tests/speech/brooklyn.flac .build/async_transcribe gs://cloud-samples-tests/speech/vr.flac