오디오 모델
음성 생성
CometAPI POST /v1/audio/speech를 사용해 선택한 text-to-speech 모델과 출력 형식으로 텍스트를 오디오로 변환합니다.
POST
/
v1
/
audio
/
speech
Python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["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")import OpenAI from "openai";
import fs from "fs";
const client = new OpenAI({
apiKey: process.env.COMETAPI_KEY,
baseURL: "https://api.cometapi.com/v1"
});
const response = await client.audio.speech.create({
model: "tts-1",
voice: "alloy",
input: "The quick brown fox jumped over the lazy dog."
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("output.mp3", buffer);curl -X POST https://api.cometapi.com/v1/audio/speech \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output output.mp3<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'tts-1',
'input' => 'The quick brown fox jumped over the lazy dog.',
'voice' => 'alloy'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/v1/audio/speech"
payload := strings.NewReader("{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/v1/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}"
response = http.request(request)
puts response.read_body"<string>"이 엔드포인트를 사용하면 OpenAI 호환 오디오 API를 통해 텍스트를 오디오 파일로 변환할 수 있습니다. 내레이션, 짧은 음성 프롬프트, 읽어주기 기능, 그리고 앱에 이미 텍스트가 있고 음성 출력을 필요로 하는 기타 워크플로에 적합합니다.
첫 번째 요청
model, input, voice의 세 필드로 시작하세요. 속도나 출력 형식을 조정하기 전에 인증, 오디오 형식, 파일 처리를 확인할 수 있도록 첫 번째 요청은 짧게 유지하세요.
응답 읽기
응답은 JSON이 아니라 바이너리 오디오입니다. SDK 예제에서는 응답을output.mp3 같은 파일에 기록하세요. 직접 HTTP 클라이언트를 사용하는 경우 응답 본문을 저장하고, 요청한 response_format에 맞게 파일 확장자를 설정하세요.
다음 단계
인증
Bearer token authentication. Use your CometAPI key.
본문
application/json
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.
Maximum string length:
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 <= 4응답
200 - audio/mpeg
The audio file content.
The response is of type file.
마지막 수정일 2026년 6월 23일
⌘I
Python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["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")import OpenAI from "openai";
import fs from "fs";
const client = new OpenAI({
apiKey: process.env.COMETAPI_KEY,
baseURL: "https://api.cometapi.com/v1"
});
const response = await client.audio.speech.create({
model: "tts-1",
voice: "alloy",
input: "The quick brown fox jumped over the lazy dog."
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("output.mp3", buffer);curl -X POST https://api.cometapi.com/v1/audio/speech \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output output.mp3<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'tts-1',
'input' => 'The quick brown fox jumped over the lazy dog.',
'voice' => 'alloy'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/v1/audio/speech"
payload := strings.NewReader("{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/v1/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"tts-1\",\n \"input\": \"The quick brown fox jumped over the lazy dog.\",\n \"voice\": \"alloy\"\n}"
response = http.request(request)
puts response.read_body"<string>"