자체 프록시를 통해 요청하는 경우 TYPECAST_API_HOST 또는 api_host를 프록시 엔드포인트로 설정하고 api_key를 생략할 수 있습니다. API 키가 비어 있거나 없으면 SDK는 X-API-KEY 헤더를 보내지 않습니다. 기본 Typecast 호스트로 요청할 때는 API 키가 계속 필요합니다.
API 키 없는 프록시
from typecast import Typecastclient = Typecast(api_host="https://your-proxy.example.com")
from typecast import Typecastfrom typecast.models import TTSRequest, SmartPromptclient = Typecast()response = client.text_to_speech(TTSRequest( text="Everything is going to be okay.", model="ssfm-v30", voice_id="tc_672c5f5ce59fac2a48faeaee", prompt=SmartPrompt( emotion_type="smart", previous_text="I just got the best news!", # 선택적 문맥 next_text="I can't wait to celebrate!" # 선택적 문맥 )))
프리셋 값으로 감정을 명시적으로 설정합니다:
from typecast import Typecastfrom typecast.models import TTSRequest, PresetPromptclient = Typecast()response = client.text_to_speech(TTSRequest( text="I am so excited to show you these features!", model="ssfm-v30", voice_id="tc_672c5f5ce59fac2a48faeaee", prompt=PresetPrompt( emotion_type="preset", emotion_preset="happy", # normal, happy, sad, angry, whisper, toneup, tonedown emotion_intensity=1.5 # 범위: 0.0 ~ 2.0 )))
오디오 데이터를 직접 다루지 않고 파일까지 바로 저장하려면 generate_to_file을 사용하세요. 모델은 기본적으로 ssfm-v30을 사용하며, .mp3 / .wav 확장자는 출력 포맷이 없을 때 포맷 추론에 사용됩니다. 사용할 캐릭터 ID는 Voices 페이지에서 확인할 수 있습니다.
client.generate_to_file( 'output.mp3', text='Hello from Typecast.', voice_id='tc_672c5f5ce59fac2a48faeaee' # voice_id는 https://typecast.ai/developers/api/voices 에서 확인하세요.)# Async clientawait async_client.generate_to_file( 'output.mp3', text='Hello from Typecast.', voice_id='tc_672c5f5ce59fac2a48faeaee' # voice_id는 https://typecast.ai/developers/api/voices 에서 확인하세요.)
from typecast import Typecastfrom typecast.models import VoicesV2Filter, TTSModel, GenderEnum, AgeEnumclient = Typecast()# 모든 음성 가져오기voices = client.voices_v2()# 기준으로 필터링filtered = client.voices_v2(VoicesV2Filter( model=TTSModel.SSFM_V30, gender=GenderEnum.FEMALE, age=AgeEnum.YOUNG_ADULT))# 음성 정보 표시for voice in voices: print(f"ID: {voice.voice_id}, Name: {voice.voice_name}") print(f"Gender: {voice.gender}, Age: {voice.age}") print(f"Models: {', '.join(m.version.value for m in voice.models)}") print(f"Use cases: {voice.use_cases}")
from typecast import Typecastfrom typecast.models import TTSRequestWithTimestampsclient = Typecast(api_key="YOUR_API_KEY")result = client.text_to_speech_with_timestamps(TTSRequestWithTimestamps( text="Hello. How are you?", model="ssfm-v30", voice_id="tc_60e5426de8b95f1d3000d7b5",))# 오디오 저장with open("output.wav", "wb") as f: f.write(result.audio_bytes())print(f"Duration: {result.audio_duration}s")for word in result.words: print(f" [{word.start_time:.3f}s – {word.end_time:.3f}s] {word.text}")
granularity="word"(기본값) 또는 granularity="char"를 지정하여 정렬 단위를 설정합니다.
# 문자 단위 정렬 — 일본어/중국어에 필수result = client.text_to_speech_with_timestamps(TTSRequestWithTimestamps( text="Hello. How are you?", model="ssfm-v30", voice_id="tc_60e5426de8b95f1d3000d7b5", granularity="char",))