import requests

# === 配置 ===
API_BASE = "https://jeniya.cn/v1/audio/speech"
API_KEY = "sk-5w2FNpdHmV4xoi07RAe2lWiqXGgvRWCbmCk9o8T39hZBhJIc"

# === 请求参数 ===
payload = {
    "model": "gpt-4o-mini-tts",  # 语音合成模型
    "input": "我是谁",             # 要合成的文字
    "voice": "alloy",            # 声音风格，可选
    "format": "mp3"              # 输出格式，可选 mp3/wav
}

# === 发起请求 ===
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

print("🎙️ 正在请求语音生成...")

response = requests.post(API_BASE, headers=headers, json=payload)

# === 保存文件 ===
if response.status_code == 200:
    output_path = "./output.mp3"
    with open(output_path, "wb") as f:
        f.write(response.content)
    print(f"✅ 成功生成语音文件: {output_path}")
else:
    print("❌ 生成失败:")
    print(response.status_code, response.text)
