Synchronously recognize Cloud Storage

Creates a stub connected to the Speech-to-Text service.

Code sample

C++

To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries.

To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Create a Speech client with the default configuration
auto client = speech::SpeechClient(speech::MakeSpeechConnection());
// Parse command line arguments.
auto const args = ParseArguments(argc, argv);
speech::v1::RecognizeRequest request;
*request.mutable_config() = args.config;
  // Pass the Google Cloud Storage URI to the request.
  request.mutable_audio()->set_uri(args.path);
// Send audio content using Recognize().
auto response = client.Recognize(request);
if (!response) throw std::move(response).status();
// Dump the transcript of all the results.
for (auto const& result : response->results()) {
  for (auto const& alternative : result.alternatives()) {
    std::cout << alternative.confidence() << "\t" << alternative.transcript()
              << "\n";
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.