创建异步语音文件

创建异步语音文件。

代码示例

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 args = ParseArguments(argc, argv);
auto const file_path = args.path;
speech::v1::LongRunningRecognizeRequest request;
*request.mutable_config() = args.config;

// Pass the Google Cloud Storage URI to the request.
request.mutable_audio()->set_uri(file_path);
// Call LongRunningRecognize(), and then `.get()` to block until the operation
// completes. The client library polls the operation in the background.
auto response = client.LongRunningRecognize(request).get();
// If the response is an error just report it:
if (!response) {
  std::cerr << "Error in LongRunningRecognize: " << response.status() << "\n";
  return 1;
}
// 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 示例浏览器