동기식 요청 인식

디스크에서 요청으로 오디오 파일을 로드합니다.

코드 샘플

C++

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

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.