同步识别 Cloud Storage

创建连接到 Speech-to-Text 服务的桩。

代码示例

C++

如需了解如何安装和使用 Speech-to-Text 客户端库,请参阅 Speech-to-Text 客户端库

如需向 Speech-to-Text 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器