import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
# クライアント作成
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# 音声生成
response = client.audio.speech.create(
    model="gpt-4o-mini-tts",   # 高品質・軽量 TTS モデル
    voice="alloy",             # 声の種類(alloy / verse / aria 等)
    input="Hello, world! This is a text-to-speech test."
)
# mp3として保存
output_path = "hello_world_tts.mp3"
with open(output_path, "wb") as f:
    f.write(response.read())
print(f"✅ 音声ファイルを保存しました → {output_path}")
声は変えられる。
voice=”alloy”   # 落ち着いた声
voice=”aria”    # 明るい声
voice=”verse”   # 自然でニュートラル