Reconocer una solicitud de sincronización

Carga el archivo de audio del disco en la solicitud.

Código de ejemplo

C++

Para saber cómo instalar y usar la biblioteca de cliente de Cloud STT, consulta Bibliotecas de cliente de Cloud STT.

Para autenticarte en Cloud STT, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en 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;
  // Load the audio file from disk into the request.
  auto content =
      std::string{std::istreambuf_iterator<char>(
                      std::ifstream(args.path, std::ios::binary).rdbuf()),
                  {}};
  request.mutable_audio()->mutable_content()->assign(std::move(content));
// 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";
  }
}

Siguientes pasos

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