{"id":3972,"date":"2026-03-25T12:40:14","date_gmt":"2026-03-25T03:40:14","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=3972"},"modified":"2026-04-08T04:59:26","modified_gmt":"2026-04-07T19:59:26","slug":"blog136%e3%80%90google-cloud-tts-3%e3%80%91%e8%87%aa%e5%89%8d%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad%ef%bc%88ubuntu24%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog136%e3%80%90google-cloud-tts-3%e3%80%91%e8%87%aa%e5%89%8d%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad%ef%bc%88ubuntu24%ef%bc%89\/","title":{"rendered":"(136)\u3010Google Cloud TTS #3\u3011\u81ea\u524d\u30b5\u30fc\u30d0\u30fc\u5074\u306e\u6e96\u5099\u4f5c\u696d\uff08Ubuntu24\uff09"},"content":{"rendered":"<h1 class=\"my_h\">\u30100\u3011\u9023\u8f09\u5185\u5bb9<\/h1>\n<p><a href=\"https:\/\/www.dogrow.net\/python\/blog134-google-cloud-tts%e3%82%92%e4%bd%bf%e3%81%84%e5%a7%8b%e3%82%81%e3%82%8b%e3%80%82\/\" target=\"_blank\">(134)\u3010Google Cloud TTS #1\u3011\u5b50\u3069\u3082\u306e\u82f1\u4f1a\u8a71\u5b66\u7fd2\u6559\u6750\u3092\u4f5c\u308a\u305f\u3044\uff01<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog135%e3%80%90google-cloud-tts-2%e3%80%91google-cloud%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad\/\" target=\"_blank\">(135)\u3010Google Cloud TTS #2\u3011Google Cloud\u5074\u306e\u6e96\u5099\u4f5c\u696d<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog136%e3%80%90google-cloud-tts-3%e3%80%91%e8%87%aa%e5%89%8d%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad%ef%bc%88ubuntu24%ef%bc%89\/\" target=\"_blank\">(136)\u3010Google Cloud TTS #3\u3011\u81ea\u524d\u30b5\u30fc\u30d0\u30fc\u5074\u306e\u6e96\u5099\u4f5c\u696d\uff08Ubuntu24\uff09<\/a> <span class='my_fs_big1B'>\u2190\u4eca\u56de\u306f\u30b3\u30b3<\/span><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog137%e3%80%90google-cloud-tts-4%e3%80%91web%e3%83%96%e3%83%a9%e3%82%a6%e3%82%b6%e3%81%8b%e3%82%89%e5%ae%9f%e8%a1%8c\/\" target=\"_blank\">(137)\u3010Google Cloud TTS #4\u3011WEB\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u5b9f\u884c<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog138%e3%80%90google-cloud-tts-5%e3%80%91%e8%a9%b1%e3%81%99%e9%80%9f%e5%ba%a6%e3%82%92%e3%82%86%e3%81%a3%e3%81%8f%e3%82%8a%e3%81%ab\/#google_vignette\" target=\"_blank\">(138)\u3010Google Cloud TTS #5\u3011\u8a71\u3059\u901f\u5ea6\u3092\u3086\u3063\u304f\u308a\u306b<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/139%e3%80%90google-cloud-tts-6%e3%80%91%e8%a9%b1%e3%81%99%e9%80%9f%e5%ba%a6\/\" target=\"_blank\">(139)\u3010Google Cloud TTS #6\u3011\u58f0\u306e\u5927\u304d\u3055\u3001\u58f0\u306e\u9ad8\u3055\u3092\u5909\u3048\u308b\u3002<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog140%e3%80%90google-cloud-tts-7%e3%80%91%e8%a9%b1%e8%80%85%ef%bc%88speaker-voice%ef%bc%89%e3%82%92%e6%8c%87%e5%ae%9a%e5%8f%af%e8%83%bd%e3%81%ab%e3%81%99%e3%82%8b%e3%80%82\/\" target=\"_blank\">(140)\u3010Google Cloud TTS #7\u3011Web\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u8a71\u8005\uff08Voice\uff09\u3092\u6307\u5b9a\u53ef\u80fd\u306b<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog141%e3%80%90google-cloud-tts-8%e3%80%91%e4%ba%8c%e4%ba%ba%e4%bb%a5%e4%b8%8a%e3%81%ae%e4%bc%9a%e8%a9%b1%e3%82%92%e5%85%a5%e5%8a%9b%e5%8f%af%e8%83%bd%e3%81%ab\/\" target=\"_blank\">(141)\u3010Google Cloud TTS #8\u3011\u4e8c\u4eba\u4ee5\u4e0a\u306e\u4f1a\u8a71\u3092\u5165\u529b\u53ef\u80fd\u306b<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/python\/blog142%e3%80%90google-cloud-tts-9%e3%80%91%e8%8b%b1%e4%bc%9a%e8%a9%b1%e6%95%99%e6%9d%90%e3%82%92%e4%bd%9c%e3%82%8b%e3%80%82%ef%bc%88%e4%b8%80%e5%85%88%e3%81%9a%e5%ae%8c%e7%b5%90%ef%bc%89\/\" target=\"_blank\">(142)\u3010Google Cloud TTS #9\u3011\u82f1\u4f1a\u8a71\u6559\u6750\u3092\u4f5c\u308b\u3002\uff08\u4e00\u5148\u305a\u5b8c\u7d50\uff09<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2026\/03\/Image5-1.jpg\" alt=\"\" \/><\/p>\n<h1 class=\"my_h\">\u30101\u3011\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u524d\u56de\u306e\u6295\u7a3f <a href=\"https:\/\/www.dogrow.net\/python\/blog135%e3%80%90google-cloud-tts-2%e3%80%91google-cloud%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad\/\" target=\"_blank\">(135)\u3010Google Cloud TTS #2\u3011Google Cloud\u5074\u306e\u6e96\u5099\u4f5c\u696d<\/a> \u3067 Google Cloud\u5074\u306e\u6e96\u5099\u4f5c\u696d\u304c\u5b8c\u4e86\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001Web\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u53d7\u3051\u3066 TTS\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u767a\u884c\u3059\u308b Python\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5b9f\u884c\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b\u3002<\/p>\n<h1 class=\"my_h\">\u30102\u3011\u74b0\u5883\u69cb\u7bc9\u306e\u65b9\u91dd<\/h1>\n<p>\u5b9f\u884c\u74b0\u5883\u4e00\u5f0f\u306f\u3001<span class='my_fc_blueB'>\/opt\/webtts<\/span> \u306b\u8a2d\u7f6e\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001Ubuntu24\u4e0a\u306e HTTP\u30b5\u30fc\u30d0\uff08Apache2.4\uff09\u306e\u5b9f\u884c\u30e6\u30fc\u30b6\u30fc\uff08www-data\uff09\u304b\u3089 Python\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3060\u3002<br \/>\n\u540c\u6642\u306b\u3001\u958b\u767a\u4e2d\u306f $USER \u3067\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u5b9f\u884c\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3002<\/p>\n<h1 class=\"my_h\">\u30103\u3011\u3084\u3063\u3066\u307f\u308b<\/h1>\n<h3 class=\"my_h\">(1) \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210<\/h3>\n<pre class='my_pre_bgBlack'>\r\n<span class='my_fc_green'># \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30eb\u30fc\u30c8\u306e\u4f5c\u6210<\/span>\r\nsudo mkdir -p \/opt\/webtts\r\n\r\n<span class='my_fc_green'># \u79d8\u5bc6\u9375\u30d5\u30a1\u30a4\u30eb\u306e\u7f6e\u304d\u5834\u6240\u3092\u4f5c\u6210\uff08\u4eee\u306b...\uff09<\/span>\r\nsudo mkdir -p \/opt\/webtts\/auth\r\n\r\n<span class='my_fc_green'># Python\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u97f3\u58f0\u51fa\u529b\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u6210<\/span>\r\nsudo mkdir -p \/opt\/webtts\/src\r\nsudo mkdir -p \/opt\/webtts\/output\r\n<\/pre>\n<h3 class=\"my_h\">(2) Python\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210<\/h3>\n<pre class='my_pre_bgBlack'>\r\n<span class='my_fc_green'># \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30eb\u30fc\u30c8\u306b\u79fb\u52d5\u3059\u308b\u3002<\/span>\r\ncd \/opt\/webtts\r\n\r\n<span class='my_fc_green'># Python-venv\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/span>\r\nsudo apt install python3-venv\r\n\r\n<span class='my_fc_green'># \u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210<\/span>\r\nsudo python3 -m venv myenv\r\n\r\n<span class='my_fc_green'># \u4eee\u60f3\u74b0\u5883\u5185\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/span>\r\nsudo .\/myenv\/bin\/pip install --upgrade google-cloud-texttospeech\r\n<\/pre>\n<h3 class=\"my_h\">(3) \u79d8\u5bc6\u9375\u306e\u914d\u7f6e\u3068\u6a29\u9650\u8a2d\u5b9a<\/h3>\n<p>\u524d\u56de\u306e\u6295\u7a3f <a href=\"https:\/\/www.dogrow.net\/python\/blog135%e3%80%90google-cloud-tts-2%e3%80%91google-cloud%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad\/\" target=\"_blank\">(135)\u3010Google Cloud TTS #2\u3011Google Cloud\u5074\u306e\u6e96\u5099\u4f5c\u696d<\/a> \u3067\u4f5c\u6210\u3057\u305f Google Cloud TTS API\u3092\u4f7f\u3046\u305f\u3081\u306e\u79d8\u5bc6\u9375\u30d5\u30a1\u30a4\u30eb\u3092<br \/>\n<span class='my_fc_blueB'>\/opt\/webts\/auth<\/span><br \/>\n\u306b\u914d\u7f6e\u3057\u305f\u5f8c\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class='my_pre_bgBlack'>\r\n<span class='my_fc_green'># \u6240\u6709\u8005\u3092 $USER\u3001\u30b0\u30eb\u30fc\u30d7\u3092 www-data \u306b\u5909\u66f4<\/span>\r\nsudo chown -R $USER:www-data \/opt\/webtts\r\n\r\n<span class='my_fc_green'># \u79d8\u5bc6\u9375\u306e\u6a29\u9650\uff1a\u30b0\u30eb\u30fc\u30d7\uff08www-data\uff09\u306e\u307f\u8aad\u307f\u53d6\u308a\u8a31\u53ef (440)<\/span>\r\nsudo chmod 440 \/opt\/webtts\/auth\/key.json\r\n\r\n<span class='my_fc_green'># \u51fa\u529b\u5148\uff1awww-data \u306b\u66f8\u304d\u8fbc\u307f\u3092\u8a31\u53ef (770)<\/span>\r\nsudo chmod 770 \/opt\/webtts\/output\r\n\r\n<span class='my_fc_green'># \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b SGID \u3092\u8a2d\u5b9a (chmod \u306e 2000 \u756a\u53f0)\r\n# \u3053\u308c\u306b\u3088\u308a\u3001\u3053\u306e\u4e2d\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u306f\u5e38\u306b www-data \u30b0\u30eb\u30fc\u30d7\u3092\u7d99\u627f\u3059\u308b\u3002<\/span>\r\nsudo find \/opt\/webtts -type d -exec chmod 2770 {} +\r\n\r\n<span class='my_fc_green'># \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u30b0\u30eb\u30fc\u30d7\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u3092\u4ed8\u4e0e<\/span>\r\nsudo find \/opt\/webtts -type f -exec chmod 660 {} +\r\n\r\n<span class='my_fc_green'># \u4eee\u60f3\u74b0\u5883\u306e\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u5b9f\u884c\u6a29\u9650\u3092\u4ed8\u4e0e<\/span>\r\nsudo chmod +x \/opt\/webtts\/myenv\/bin\/python\r\n<\/pre>\n<h1 class=\"my_h\">\u30104\u3011\u52d5\u4f5c\u78ba\u8a8d<\/h1>\n<p>\u524d\u56de\u306e\u6295\u7a3f\u3067 Google Cloud\u5074\u306e\u8a2d\u5b9a\u304c\u51fa\u6765\u305f\u3002<br \/>\n\u4eca\u56de\u306e\u6295\u7a3f\u3067 Ubuntu24\u5074\u306e\u8a2d\u5b9a\u304c\u51fa\u6765\u305f\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u52d5\u4f5c\u78ba\u8a8d\u7528\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3066\u307f\u3088\u3046\uff01<\/p>\n<pre class='my_pre_bgBlack'>\r\n<span class='my_fc_green'># \u307e\u305a\u306f\u3001\u30103\u3011(2)\u3067\u4f5c\u6210\u3057\u305f Python\u4eee\u60f3\u74b0\u5883\u306b\u5165\u308b\u3002<\/span>\r\nsource \/opt\/webtts\/myenv\/bin\/activate\r\n\r\n<span class='my_fc_green'># \u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304f\u305f\u3081\u306b\u4f5c\u3063\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3059\u308b\u3002<\/span>\r\ncd \/opt\/webtts\/src\r\n\r\n<span class='my_fc_green'># Python\u3092\u8d77\u52d5\u3059\u308b\u3002<\/span>\r\npython\r\n<\/pre>\n<p>Python Shell\u304c\u8d77\u52d5\u3057\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4e00\u884c\u305a\u3064\u5165\u529b\u3057\u306a\u304c\u3089\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\nimport sys\r\nfrom google.cloud import texttospeech\r\n\r\n#-----------------------------------------------------------------------\r\n# \u9375\u30d5\u30a1\u30a4\u30eb\u306e\u7d76\u5bfe\u30d1\u30b9\u3092\u6307\u5b9a\r\nKEY_PATH = &quot;\/opt\/webtts\/auth\/key.json&quot;\r\nos.environ&#x5B;&quot;GOOGLE_APPLICATION_CREDENTIALS&quot;] = KEY_PATH\r\n\r\n#-----------------------------------------------------------------------\r\n# \u82f1\u6587\u3068 \u51fa\u529bMP\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\r\ntext = &quot;Can you read this book for me?&quot;\r\nmp3file = &quot;sound.mp3&quot;\r\n\r\n#-----------------------------------------------------------------------\r\n# TTS\u5b9f\u884c\r\nclient = texttospeech.TextToSpeechClient()\r\nsynthesis_input = texttospeech.SynthesisInput(text=text)\r\nvoice           = texttospeech.VoiceSelectionParams(language_code=&quot;en-US&quot;, name=&quot;en-US-Chirp3-HD-Rasalgethi&quot;)\r\naudio_config    = texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3)\r\nresponse = client.synthesize_speech(input=synthesis_input, voice=voice, audio_config=audio_config)\r\n\r\n#-----------------------------------------------------------------------\r\n# TTS\u3067\u751f\u6210\u3055\u308c\u305f\u97f3\u58f0\u3092MP3\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\r\noutput_file = os.path.join(&quot;\/opt\/webtts\/output&quot;, mp3file)\r\nwith open(output_file, &quot;wb&quot;) as out:\r\n    out.write(response.audio_content)\r\n<\/pre>\n<p><span class='my_fc_blueBBig'>\u6210\u529f\uff01<br \/>\n\u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u304c\u51fa\u529b\u3055\u308c\u305f\u3002<\/span><\/p>\n<p>Can you read this book for me?<br \/>\n\u3068\u3001\u304b\u306a\u308a\u306e\u65e9\u53e3\u3067\u518d\u751f\u3055\u308c\u305f\u3002<\/p>\n<p><span class='my_fc_redB'>\u5b50\u3069\u3082\u306e\u5b66\u7fd2\u7528\u306b\u306f\u901f\u5ea6\u8abf\u6574\u304c\u5fc5\u8981\u3060\u306a&#8230;<\/span><\/p>\n<pre class='my_pre_bgBlack'>\r\n$ ls -l \/opt\/webtts\/output\/\r\ntotal 8\r\n-rw-rw-r-- 1 user www-data 5952  3\u6708 25 12:33 sound.mp3\r\n\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u30100\u3011\u9023\u8f09\u5185\u5bb9 (134)\u3010Google Cloud TTS #1\u3011\u5b50\u3069\u3082\u306e\u82f1\u4f1a\u8a71\u5b66\u7fd2\u6559\u6750\u3092\u4f5c\u308a\u305f\u3044\uff01 (135)\u3010Google Cloud TTS #2\u3011Google Cloud\u5074\u306e\u6e96\u5099\u4f5c\u696d (136)\u3010Google \u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog136%e3%80%90google-cloud-tts-3%e3%80%91%e8%87%aa%e5%89%8d%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e5%81%b4%e3%81%ae%e6%ba%96%e5%82%99%e4%bd%9c%e6%a5%ad%ef%bc%88ubuntu24%ef%bc%89\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-3972","post","type-post","status-publish","format-standard","hentry","category-google-cloud-tts"],"views":113,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/3972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=3972"}],"version-history":[{"count":20,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/3972\/revisions"}],"predecessor-version":[{"id":4205,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/3972\/revisions\/4205"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=3972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=3972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=3972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}