GoogleのText-to-Speech APIを使ってみる

1. Google Cloud プロジェクト作成
2. Text-to-Speech API を有効化
3. サービスアカウントキー(JSON)をダウンロード
4. 必要なライブラリをインストール
$ pip3 install google-cloud-texttospeech

from google.cloud import texttospeech
from google.oauth2 import service_account

# 認証キー読み込み
credentials = service_account.Credentials.from_service_account_file("gcp-test.json")
client = texttospeech.TextToSpeechClient(credentials=credentials)

# 読み上げるテキスト
input_text = texttospeech.SynthesisInput(text="こんにちは、これはテストです。")

# 日本語のWavenet音声
voice = texttospeech.VoiceSelectionParams(
    language_code="ja-JP",
    name="ja-JP-Wavenet-B"
)

audio_config = texttospeech.AudioConfig(
    audio_encoding=texttospeech.AudioEncoding.MP3
)

# 音声生成
response = client.synthesize_speech(
    input=input_text,
    voice=voice,
    audio_config=audio_config
)

# 保存
with open("output.mp3", "wb") as out:
    out.write(response.audio_content)
    print("✅ output.mp3 を作成しました")

そりゃGoogleもやってるわな… という感想しか出てこない