This tutorial shows how to transcribe the audio recorded from a phone using Speech-to-Text.
Audio files can come from many different sources. Audio data can come from a phone (like voicemail) or a soundtrack included in a video file.
Speech-to-Text can use one of several machine learning models to transcribe your audio file, to best match the original source of the audio. You can get better results from your speech transcription by specifying the source of the original audio. This allows the Speech-to-Text to process your audio files using a machine learning model trained for data similar to your audio file.
Objectives
- Send a audio transcription request for audio recorded from a phone (like voicemail) to Speech-to-Text.
- Specify an enhanced speech recognition model for an audio transcription request.
Costs
This tutorial uses billable components of Cloud Platform, including:
- Speech-to-Text
Use the Pricing Calculator to generate a cost
estimate based on your projected usage.
Before you begin
This tutorial has several prerequisites:
- You've set up a Speech-to-Text project in the Google Cloud console.
- You've set up your environment using Application Default Credentials in the Google Cloud console.
- You have set up the development environment for your chosen programming language.
- You've installed the Google Cloud Client Library for your chosen programming language.
Send a request
To best transcribe audio captured on a phone, like a phone call or
voicemail, you can set the model
field in your
RecognitionConfig
payload to
phone_call
. The model
field tells Speech-to-Text API which
speech recognition model to use for the transcription request.
You can improve the results of phone audio transcription by using
an enhanced model. To use an enhanced
model, you set the useEnhanced
field to true
in your
RecognitionConfig
payload.
The following code samples demonstrate how to select a specific transcription model when calling Speech-to-Text.
Protocol
Refer to the speech:recognize
API endpoint for complete details.
To perform synchronous speech recognition, make a POST
request and provide the
appropriate request body. The following shows an example of a POST
request using
curl
. The example uses the Google Cloud CLI to generate an access
token. For instructions on installing the gcloud CLI,
see the quickstart.
curl -s -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ https://speech.googleapis.com/v1/speech:recognize \ --data '{ "config": { "encoding": "LINEAR16", "languageCode": "en-US", "enableWordTimeOffsets": false, "enableAutomaticPunctuation": true, "model": "phone_call", "useEnhanced": true }, "audio": { "uri": "gs://cloud-samples-tests/speech/commercial_mono.wav" } }'
See the RecognitionConfig
reference documentation for
more information on configuring the request body.
If the request is successful, the server returns a 200 OK
HTTP
status code and the response in JSON format:
{ "results": [ { "alternatives": [ { "transcript": "Hi, I'd like to buy a Chromecast. I was wondering whether you could help me with that.", "confidence": 0.8930228 } ], "resultEndTime": "5.640s" }, { "alternatives": [ { "transcript": " Certainly, which color would you like? We are blue black and red.", "confidence": 0.9101991 } ], "resultEndTime": "10.220s" }, { "alternatives": [ { "transcript": " Let's go with the black one.", "confidence": 0.8818244 } ], "resultEndTime": "13.870s" }, { "alternatives": [ { "transcript": " Would you like the new Chromecast Ultra model or the regular Chromecast?", "confidence": 0.94733626 } ], "resultEndTime": "18.460s" }, { "alternatives": [ { "transcript": " Regular Chromecast is fine. Thank you. Okay. Sure. Would you like to ship it regular or Express?", "confidence": 0.9519095 } ], "resultEndTime": "25.930s" }, { "alternatives": [ { "transcript": " Express, please.", "confidence": 0.9101229 } ], "resultEndTime": "28.260s" }, { "alternatives": [ { "transcript": " Terrific. It's on the way. Thank you. Thank you very much. Bye.", "confidence": 0.9321616 } ], "resultEndTime": "34.150s" } ] }
Go
To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries. For more information, see the Speech-to-Text Go API reference documentation.
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries. For more information, see the Speech-to-Text Java API reference documentation.
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries. For more information, see the Speech-to-Text Node.js API reference documentation.
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries. For more information, see the Speech-to-Text Python API reference documentation.
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Speech-to-Text reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Speech-to-Text reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Speech-to-Text reference documentation for Ruby.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the project
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Delete instances
To delete a Compute Engine instance:
- In the Google Cloud console, go to the VM instances page.
- Select the checkbox for the instance that you want to delete.
- To delete the instance, click More actions, click Delete, and then follow the instructions.
Delete firewall rules for the default network
To delete a firewall rule:
- In the Google Cloud console, go to the Firewall page.
- Select the checkbox for the firewall rule that you want to delete.
- To delete the firewall rule, click Delete.