Reconocer de forma síncrona a Cloud Storage

Crea un stub conectado al servicio de Speech-to-Text.

Muestra de código

C++

Para obtener información sobre cómo instalar y usar la biblioteca cliente de Speech-to-Text, consulta las bibliotecas cliente de Speech-to-Text.

Para autenticar en Speech-to-Text, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

// 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";
  }
}

¿Qué sigue?

Para buscar y filtrar muestras de código para otros Google Cloud productos, consulta el Google Cloud navegador de muestras.