This page describes how to get automatic punctuation in transcription results from Speech-to-Text. When you enable this feature, Speech-to-Text automatically infers the presence of periods, commas, and question marks in your audio data and adds them to the transcript.
By default, Speech-to-Text does not include punctuation marks in the results from speech recognition. However, you can request that Speech-to-Text automatically detect and insert punctuation in transcription results. When you enable automatic punctuation Speech-to-Text will also automatically capitalize the first letter after each period and question mark.
To enable automatic punctuation, set the enableAutomaticPunctuation
field to
true
in the RecognitionConfig
parameters for the
request. The Speech-to-Text API supports automatic punctuation for all speech
recognition methods:
speech:recognize
,
speech:longrunningrecognize
,
and Streaming.
The following code samples demonstrate how to get automatic punctuation details in a transcription request.
Protocol
Refer to thespeech: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 print-access-token) \ https://speech.googleapis.com/v1/speech:recognize \ --data '{ "config": { "encoding":"FLAC", "sampleRateHertz": 16000, "languageCode": "en-US", "enableAutomaticPunctuation": true }, "audio": { "uri":"gs://cloud-samples-tests/speech/brooklyn.flac" } }'
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": "How old is the Brooklyn Bridge?", "confidence": 0.98360395 } ] } ] }
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.
What's next
Review how to make synchronous transcription requests.