Using enhanced models

This page describes how to request an enhanced speech recognition model when you send a transcription request to Cloud Speech-to-Text.

When you opt-in for data logging, you receive access to a special set of machine learning models for speech recognition. Google creates and improves these enhanced models based upon data collected through data logging. You can then request that Speech-to-Text use an enhanced model when transcribing an audio file for you, which can produce higher quality results.

For example, if you send a transcription request for an audio file of a phone call, Speech-to-Text can route your request to an enhanced phone call model. Using the improved phone call model, Speech-to-Text can more accurately recognize speech captured from a phone call and therefore produce more accurate transcription of the audio data.

To use the enhanced recognition models, set the useEnhanced field to true, and then set the model field to your selected enhanced model in the RecognitionConfig parameters for the request. Speech-to-Text supports enhanced models for all speech recognition methods: speech:recognize, speech:longrunningrecognize, and StreamingRecognizeRequest.

The following code samples demonstrate how to request to use an enhanced model for a transcription request.


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 access token for a service account set up for the project using the Google Cloud Platform Cloud SDK. For instructions on installing the Cloud SDK, setting up a project with a service account, and obtaining an access token, see the Quickstart.

curl -s -H "Content-Type: application/json" \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ \
    --data "{
  'config': {
    'encoding': 'LINEAR16',
    'languageCode': 'en-US',
    'enableWordTimeOffsets': false,
    'enableAutomaticPunctuation': true,
    'model': 'phone_call',
    'useEnhanced': true
  'audio': {

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"


 * Transcribe the given audio file using an enhanced model.
 * @param fileName the path to an audio file.
public static void transcribeFileWithEnhancedModel(String fileName) throws Exception {
  Path path = Paths.get(fileName);
  byte[] content = Files.readAllBytes(path);

  try (SpeechClient speechClient = SpeechClient.create()) {
    // Get the contents of the local audio file
    RecognitionAudio recognitionAudio =

    // Configure request to enable enhanced models
    RecognitionConfig config =
            // Enhanced models are only available to projects that
            // opt in for audio data collection.
            // A model must be specified to use enhanced model.

    // Perform the transcription request
    RecognizeResponse recognizeResponse = speechClient.recognize(config, recognitionAudio);

    // Print out the results
    for (SpeechRecognitionResult result : recognizeResponse.getResultsList()) {
      // There can be several alternative transcripts for a given chunk of speech. Just use the
      // first (most likely) one here.
      SpeechRecognitionAlternative alternative = result.getAlternatives(0);
      System.out.format("Transcript: %s\n\n", alternative.getTranscript());


// Imports the Google Cloud client library for Beta API
 * TODO(developer): Update client library import to use new
 * version of API when desired features become available
const speech = require('@google-cloud/speech').v1p1beta1;
const fs = require('fs');

// Creates a client
const client = new speech.SpeechClient();

 * TODO(developer): Uncomment the following lines before running the sample.
// const filename = 'Local path to audio file, e.g. /path/to/audio.raw';
// const encoding = 'Encoding of the audio file, e.g. LINEAR16';
// const sampleRateHertz = 16000;
// const languageCode = 'BCP-47 language code, e.g. en-US';

const config = {
  encoding: encoding,
  languageCode: languageCode,
  useEnhanced: true,
  model: 'phone_call',
const audio = {
  content: fs.readFileSync(filename).toString('base64'),

const request = {
  config: config,
  audio: audio,

// Detects speech in the audio file
const [response] = await client.recognize(request);
response.results.forEach(result => {
  const alternative = result.alternatives[0];


from import speech_v1p1beta1 as speech
client = speech.SpeechClient()

speech_file = 'resources/commercial_mono.wav'

with, 'rb') as audio_file:
    content =

audio = speech.types.RecognitionAudio(content=content)
config = speech.types.RecognitionConfig(
    # Enhanced models are only available to projects that
    # opt in for audio data collection.
    # A model must be specified to use enhanced model.

response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print('-' * 20)
    print('First alternative of result {}'.format(i))
    print('Transcript: {}'.format(alternative.transcript))


use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;

 * Transcribe the given audio file using an enhanced model
function transcribe_enhanced_model($audioFile)
    // get contents of a file into a string
    $content = file_get_contents($audioFile);

    // set string as audio content
    $audio = (new RecognitionAudio())

    // set config
    $config = (new RecognitionConfig())

    // create the speech client
    $client = new SpeechClient();

    // make the API call
    $response = $client->recognize($config, $audio);
    $results = $response->getResults();

    // print results
    foreach ($results as $result) {
        $alternatives = $result->getAlternatives();
        $mostLikely = $alternatives[0];
        $transcript = $mostLikely->getTranscript();
        $confidence = $mostLikely->getConfidence();
        printf('Transcript: %s' . PHP_EOL, $transcript);
        printf('Confidence: %s' . PHP_EOL, $confidence);


What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Speech-to-Text API