解碼 Base64 編碼的音訊內容
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
音訊資料為二進位資料。您可以直接從 gRPC 回應讀取二進位資料,但在回應 REST 要求時,系統會使用 JSON。由於 JSON 是一種文字格式,不直接支援二進位資料,因此 Text-to-Speech 會傳回以 Base64 編碼的回應字串。您必須先將回應中的 base64 編碼文字資料轉換成二進位資料,然後才能在裝置上播放。
Text-to-Speech 的 JSON 回應會在 audioContent
欄位中加入 base64 編碼的音訊內容。例如:
{
"audioContent": "//NExAARqoIIAAhEuWAAAGNmBGMY4EBcxvABAXBPmPIAF//yAuh9Tn5CEap3/o..."
}
若要將 base64 解碼成音訊檔案:
Linux
僅將 base-64 編碼內容複製到文字檔。
使用 -d
標記,透過 base64 指令列工具解碼來源文字檔:
$ base64 SOURCE_BASE64_TEXT_FILE -d > DESTINATION_AUDIO_FILE
Mac OSX
僅將 base-64 編碼內容複製到文字檔。
使用 base64 指令列工具解碼來源文字檔:
$ base64 --decode -i SOURCE_BASE64_TEXT_FILE > DESTINATION_AUDIO_FILE
Windows
僅將 base-64 編碼內容複製到文字檔。
使用 certutil
指令解碼來源文字檔。
certutil -decode SOURCE_BASE64_TEXT_FILE DESTINATION_AUDIO_FILE
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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```"]]