对使用 Base64 编码的音频内容进行解码
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
音频数据是二进制数据。您可以从 gRPC 响应直接读取二进制数据;但系统响应 REST 请求时使用的是 JSON 格式。因为 JSON 是文本格式,不直接支持二进制数据,所以 Text-to-Speech 会返回以 Base64 中编码的响应字符串。您必须先将响应中的 base64 编码文本数据转换为二进制,然后才能在设备上播放它。
Text-to-Speech 返回的 JSON 响应包括 audioContent
字段中的 base64 编码音频内容。例如:
{
"audioContent": "//NExAARqoIIAAhEuWAAAGNmBGMY4EBcxvABAXBPmPIAF//yAuh9Tn5CEap3/o..."
}
要将 base64 内容解码到音频文件,请执行以下操作:
Linux
仅将使用 base64 编码的内容复制到文本文件中。
使用 base64 命令行工具通过 -d
标志对源文本文件进行解码:
$ base64 SOURCE_BASE64_TEXT_FILE -d > DESTINATION_AUDIO_FILE
Mac OSX
仅将使用 base64 编码的内容复制到文本文件中。
使用 base64 命令行工具对源文本文件进行解码:
$ base64 --decode -i SOURCE_BASE64_TEXT_FILE > DESTINATION_AUDIO_FILE
Windows
仅将使用 base64 编码的内容复制到文本文件中。
使用 certutil
命令对源文本文件进行解码。
certutil -decode SOURCE_BASE64_TEXT_FILE DESTINATION_AUDIO_FILE
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-04。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Decode base64-encoded audio content\n\nAudio data is binary data. You can read the binary data directly from a gRPC\nresponse; however, JSON is used when responding to a REST request. Because JSON\nis a text format that does not directly support binary data,\nText-to-Speech returns a response string encoded in\n[Base64](https://en.wikipedia.org/wiki/Base64). You must convert the base64-encoded\ntext data from the response to binary before you can play it on a device.\n\nJSON responses from the Text-to-Speech include base64-encoded audio\ncontent in the `audioContent` field. For example: \n\n```json\n{\n \"audioContent\": \"//NExAARqoIIAAhEuWAAAGNmBGMY4EBcxvABAXBPmPIAF//yAuh9Tn5CEap3/o...\"\n}\n```\n\nTo decode base64 into an audio file: \n\n### Linux\n\n1. Copy only the base-64 encoded content into a text file.\n\n2. Decode the source text file using the base64 command line tool\n by using the `-d` flag:\n\n```bash\n $ base64 SOURCE_BASE64_TEXT_FILE -d \u003e DESTINATION_AUDIO_FILE\n```\n\n### Mac OSX\n\n1. Copy only the base-64 encoded content into a text file.\n\n2. Decode the source text file using the base64 command line tool:\n\n```bash\n $ base64 --decode -i SOURCE_BASE64_TEXT_FILE \u003e DESTINATION_AUDIO_FILE\n```\n\n### Windows\n\n1. Copy only the base-64 encoded content into a text file.\n\n2. Decode the source text file using the\n [`certutil`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/certutil) command.\n\n```bash\n certutil -decode SOURCE_BASE64_TEXT_FILE DESTINATION_AUDIO_FILE\n```"]]