Transcribe speech to text by using client libraries
This page shows you how to send a speech recognition request to Speech-to-Text in your favorite programming language using the Google Cloud Client Libraries.
Speech-to-Text enables easy integration of Google speech recognition technologies into developer applications. You can send audio data to the Speech-to-Text API, which then returns a text transcription of that audio file. For more information about the service, see Speech-to-Text basics.
Before you begin
Before you can send a request to the Speech-to-Text API, you must have completed the following actions. See the before you begin page for details.
- Enable Speech-to-Text on a Google Cloud project.
- Make sure billing is enabled for Speech-to-Text.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
- (Optional) Create a new Google Cloud Storage bucket to store your audio data.
Install the client library
Go
go get cloud.google.com/go/speech/apiv1
Java
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
Before installing the library, make sure you've prepared your environment for Node.js development.
npm install --save @google-cloud/speech
Python
Before installing the library, make sure you've prepared your environment for Python development.
pip install --upgrade google-cloud-speech
Make an audio transcription request
Now you can use Speech-to-Text to transcribe an audio file
to text. Use the following code to send a
recognize
request to the Speech-to-Text API.
Go
Java
Node.js
Before running the example, make sure you've prepared your environment for Node.js development.
Python
Before running the example, make sure you've prepared your environment for Python development.
Congratulations! You've sent your first request to Speech-to-Text.
If you receive an error or an empty response from Speech-to-Text, take a look at the troubleshooting and error mitigation steps.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
- Use the Google Cloud console to delete your project if you do not need it.
What's next
- Practice transcribing short audio files.
- Learn how to batch long audio files for speech recognition.
- Learn how to transcribe streaming audio like from a microphone.
- Get started with the Speech-to-Text in your language of choice by using a Speech-to-Text client library.
- Work through the sample applications.
- For best performance, accuracy, and other tips, see the best practices documentation.