스트리밍은 단일 TTS 클립이 충분히 길어, 전체가 완성될 때까지 기다리는 시간이 체감될 정도일 때 가장 유용합니다. 예를 들어 여러 문장으로 이루어진 단락을 한 번의 호출로 합성하는 경우입니다.각 발화가 짧은 문장인 인터랙티브 에이전트나 챗봇의 경우, 보통 빠른 논스트리밍 모델을 사용하는 편이 전체 지연시간 면에서 더 유리합니다.
sona_speech_2_flash — 속도와 품질의 균형을 잡은 모델입니다.
supertonic_api_3 — 추론 속도가 가장 빠르면서도 음성 안정성이 높은 모델입니다. 첫 오디오 도달 시간(time-to-first-audio)이 최우선일 때 사용해 주십시오.
자세한 논의는 지연시간 최적화를 참고해 주십시오. LLM 응답을 TTS로 스트리밍하기에서 소개하는 문장 단위 패턴은 stream_speech를 전혀 사용하지 않으며, 문장마다 빠른 논스트리밍 모델을 호출하는 방식에 의존합니다.
from supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDwith Supertone(api_key=API_KEY) as client: response = client.text_to_speech.stream_speech( voice_id=VOICE_ID, text="This response is streamed chunk by chunk.", language="en", model="sona_speech_1", output_format="wav", ) with open("streamed.wav", "wb") as f: for chunk in response.result.iter_bytes(): f.write(chunk)
import asynciofrom supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDasync def main(): async with Supertone(api_key=API_KEY) as client: response = await client.text_to_speech.stream_speech_async( voice_id=VOICE_ID, text="This response is streamed chunk by chunk.", language="en", model="sona_speech_1", ) with open("streamed.wav", "wb") as f: async for chunk in response.result.aiter_bytes(): f.write(chunk)asyncio.run(main())
import { Supertone } from "@supertone/supertone";import * as fs from "node:fs";const VOICE_ID = "20160a4c5ba38967330c84"; // replace with your voice IDconst client = new Supertone({ apiKey: API_KEY });const response = await client.textToSpeech.streamSpeech({ voiceId: VOICE_ID, apiConvertTextToSpeechUsingCharacterRequest: { text: "This response is streamed chunk by chunk.", language: "en", model: "sona_speech_1", outputFormat: "wav", },});if (response.result && typeof response.result === "object" && "getReader" in response.result) { const reader = (response.result as ReadableStream<Uint8Array>).getReader(); const chunks: Uint8Array[] = []; while (true) { const { done, value } = await reader.read(); if (done) break; if (value) chunks.push(value); } fs.writeFileSync("streamed.wav", Buffer.concat(chunks));}
SDK는 스트리밍 시에도 300자를 초과하는 텍스트를 자동으로 분할합니다. 내부적으로 텍스트를 분할하고 순차적인 스트리밍 요청을 보낸 뒤, 청크를 호출자의 이터레이터로 전달하므로 읽기 루프 코드는 그대로 유지할 수 있습니다.자세한 내용은 Long text를 참고해 주십시오.