base64 エンコードの音声コンテンツをデコードする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
音声データはバイナリデータです。バイナリデータは、gRPC レスポンスから直接読み取ることができますが、REST リクエストへのレスポンスには JSON が使用されます。JSON はバイナリデータを直接サポートしていないテキスト形式であるため、Text-to-Speech は Base64 でエンコードされたレスポンス文字列を返します。レスポンス内の、Base64 でエンコードされたテキストデータをデバイスで再生するには、そのテキストデータをバイナリに変換する必要があります。
Text-to-Speech からの JSON レスポンスでは、audioContent
フィールドに base64 でエンコードされた音声コンテンツが格納されています。例:
{
"audioContent": "//NExAARqoIIAAhEuWAAAGNmBGMY4EBcxvABAXBPmPIAF//yAuh9Tn5CEap3/o..."
}
base64 を音声ファイルにデコードするには:
Linux
base-64 エンコード形式のコンテンツのみをテキスト ファイルにコピーします。
base64 コマンドライン ツールで -d
フラグを使用してソーステキスト ファイルをデコードします。
$ 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
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","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 UTC。"],[],[],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```"]]