predict_duration은 주어진 텍스트에 대해 오디오를 생성하지 않고 예상 길이를 반환합니다. 다음과 같은 용도로 사용하세요.
생성 전에 “약 12초 소요됩니다” 같은 추정치를 사용자에게 표시.
크레딧 비용 예측(이 엔드포인트는 크레딧을 차감하지 않습니다).
문장이 UI 슬롯이나 예산에 맞는지 판단.
predict_duration은 자동 청크 분할을 하지 않습니다 — 동일하게 300자 제한이 적용됩니다. 더 긴 스크립트는 직접 분할한 뒤 예측된 길이를 합산하세요.
Python
TypeScript
cURL
import osfrom supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDwith Supertone(api_key=os.environ["SUPERTONE_API_KEY"]) as client: response = client.text_to_speech.predict_duration( voice_id=VOICE_ID, text="This is a sentence to estimate.", language="en", )print(f"Estimated duration: {response.duration:.2f}s")
import { Supertone } from "@supertone/supertone";const VOICE_ID = "20160a4c5ba38967330c84"; // replace with your voice IDconst client = new Supertone({ apiKey: process.env.SUPERTONE_API_KEY });const response = await client.textToSpeech.predictDuration({ voiceId: VOICE_ID, predictTTSDurationRequest: { text: "This is a sentence to estimate.", language: "en", },});console.log(`Estimated duration: ${response.duration?.toFixed(2)}s`);
VOICE_ID="20160a4c5ba38967330c84"curl -X POST "https://supertoneapi.com/v1/predict-duration/$VOICE_ID" \ -H "x-sup-api-key: $SUPERTONE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "This is a sentence to estimate.", "language": "en" }'
Response:
{ "duration": 2.18 }
요청 본문의 형태는 Create speech와 동일합니다 — text, language, style, model, voice_settings — 단, output_format, include_phonemes, normalized_text는 제외됩니다(이들은 예측 길이에 영향을 주지 않습니다).정확한 예측을 위한 팁:
속도(speed)는 결과를 바꿉니다.voice_settings.speed는 길이를 배수로 변경합니다. 미리보기와 실제 생성에서 다른 속도를 사용하면 실제 길이가 달라집니다. 두 호출에서 동일한 speed를 사용하세요.
모델을 일치시키세요.predict_duration은 create_speech와 동일한 model 필드를 받습니다. 특정 모델로 생성할 예정이라면 동일 모델로 예측하세요.
배치 작업의 사전 점검이나 사용자별 예산 관리를 위해서는, 먼저 predict_duration을 호출해 길이를 합산한 뒤 진행 여부를 결정하세요.