Riconoscere una richiesta di sincronizzazione

Carica il file audio dal disco nella richiesta.

Esempio di codice

C++

Per scoprire come installare e utilizzare la libreria client per Speech-to-Text, consulta la sezione Librerie client di Speech-to-Text.

Per autenticarti in Speech-to-Text, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

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

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .