chatgpt/text_to_speech.py

17 lines
379 B
Python

from dotenv import load_dotenv
from openai import OpenAI
from pathlib import Path
load_dotenv()
client = OpenAI()
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="onyx",
response_format="opus",
input="This is just a test. I'm curious what it sounds like."
)
response.stream_to_file(speech_file_path)