No results found
We couldn't find anything using that term, please try searching for something else.
使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类 。 使用 API 将语音转录为文字 本页面介绍了如何使用 REST 接口和 curl 命令向 Speech-to-Text 发送语音识别请求。
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类 。
本页面介绍了如何使用 REST 接口和 curl
命令向 Speech-to-Text 发送语音识别请求。
Speech-to-Text 能够将 Google 语音识别技术轻松集成到开发者应用中。您可以向 Speech-to-Text API 发送音频数据,然后该 API 会返回该音频文件的文字转录。如需详细了解该服务,请参阅 Speech-to-Text 基础知识。
您必须先完成以下操作,然后才能向 Speech-to-Text API 发送请求。如需了解详情,请参阅准备工作页面。
现在您可以使用 Speech-to-Text 将音频文件转录为文字。请使用以下代码示例向 Speech-to-Text API 发送 recognize
REST 请求。
创建包含以下文本的 JSON 请求文件,然后将其另存为 sync-request.json
纯文本文件:
{ "config": { "encoding":"FLAC", "sampleRateHertz": 16000, "languageCode": "en-US", "enableWordTimeOffsets": false }, "audio": { "uri":"gs://cloud-samples-tests/speech/brooklyn.flac" } }
此 JSON is 片段表明,音频文件具有 片段表明,音频文件具有 FLAC 编码格式,采样率为 16000 Hz,以及音频文件存储在 Google Cloud Storage 中的给定 URI 处。该音频文件可公开访问,因此您不需要身份验证凭据即可访问该文件 。
使用 curl
发出speech:recognize
请求,并向其传递您在步骤 1 中设置的 JSON 请求的文件名 :
示例 curl
命令使用 gcloud auth print-access-token
命令来获取身份验证令牌。
curl -s -H "Content-Type: application/json" \ -H "Authorization: Bearer "$(gcloud auth print-access-token) \ https://speech.googleapis.com/v1/speech:recognize \ -d @sync-request.json
请注意,要将文件名传递给curl
, 您可以使用-d
选项(表示“数据”)并在文件名前面加上 @
符号。此文件应该位于您执行 curl
命令所在的目录中。
您应该会看到如下所示的响应:
{ "results": [ { "alternatives": [ { " transcript ": "how old is the Brooklyn Bridge", " confidence ": 0.98267895 } ] } ] }
恭喜!您已向 Speech-to-Text 发送了您的第一个请求!
如果您收到来自 Speech-to-Text 的错误或空响应,请查看问题排查和纠错步骤。
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作 。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和 / 或其关联公司的注册商标 。
最后更新时间 (UTC):2024-12-22。
[ [ [ ” 易于理解”,”easytounderstand”,”thumb – up”],[“解决了我的问题”,”solvedmyproblem”,”thumb – up”],[“其他”,”otherup”,”thumb – up”]],[[“hard to understand”,”hardtounderstand”,”thumb – down”],[“incorrect information or sample code”,”incorrectInformationOrSampleCode”,”thumb – down”],[“misse the information / sample I need”,”missingtheinformationsamplesineed”,”thumb – down”],[“翻译问题”,”translationissue”,”thumb – down”],[“其他”,”otherdown”,”thumb – down”]],[“最后更新时间 ( utc):2024 – 12 – 22 。 ” ] , [ ] , [ ] ]