Sử dụng CometAPI POST /v1/audio/speech để chuyển văn bản thành âm thanh sống động như thật bằng các model TTS. Chọn từ 10 giọng nói, điều chỉnh tốc độ và xuất ra MP3, OPUS, AAC, FLAC, WAV hoặc PCM.
from openai import OpenAI
client = OpenAI(
api_key="<COMETAPI_KEY>",
base_url="https://api.cometapi.com/v1"
)
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="The quick brown fox jumped over the lazy dog."
)
response.stream_to_file("output.mp3")"<string>"Bearer token authentication. Use your CometAPI key.
The TTS model to use. Choose a current speech model from the Models page.
The text to generate audio for. Maximum length is 4096 characters.
4096The voice to use for speech synthesis.
alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer The audio output format.
mp3, opus, aac, flac, wav, pcm The speed of the generated audio. Select a value between 0.25 and 4.0.
0.25 <= x <= 4The audio file content.
The response is of type file.
from openai import OpenAI
client = OpenAI(
api_key="<COMETAPI_KEY>",
base_url="https://api.cometapi.com/v1"
)
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="The quick brown fox jumped over the lazy dog."
)
response.stream_to_file("output.mp3")"<string>"