최신 등록 버전은 PyPI 기준 0.3.8입니다. 버전 0.3.8 이상이 설치되어 있는지 확인하세요. pip show typecast-python으로 버전을 확인할 수 있습니다. 이전 버전이 있다면 pip install --upgrade typecast-python을 실행하여 업데이트하세요.
from typecast import Typecast# 환경 변수에서client = Typecast()
from typecast import Typecast# 또는 직접 전달client = Typecast(api_key="your-api-key-here")
자체 프록시를 통해 요청하는 경우 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 에서 확인하세요.)
한 voice로 읽는 문장 안에 쉼만 넣고 싶다면 텍스트에 pause markup을 직접 작성합니다. <|5s|>, <|1s|>, <|0.3s|>, <|0.34413s|>처럼 쓰며 값은 초 단위이고 반드시 s로 끝납니다. 별도 pause 함수를 호출하지 않아도 텍스트만 보고 쉼 위치를 확인할 수 있습니다.
response = ( client.compose_speech() .defaults(voice_id="tc_672c5f5ce59fac2a48faeaee", model="ssfm-v30") .say("안녕하세요<|5s|>반갑습니다<|1s|>오늘<|2s|>날씨는 어떤 것 같으세요?") .generate())
한 파일 안에서 서로 다른 voice나 구간별 pitch, tempo, prompt, seed 같은 옵션을 조합해야 할 때 사용합니다. composer는 각 구간을 WAV로 생성하고 앞뒤 무음 PCM 샘플을 trim한 뒤 합성합니다. MP3가 필요하면 먼저 WAV를 생성한 다음 앱 또는 서버 파이프라인에서 변환하세요.
from typecast import Typecastfrom typecast.models import Outputclient = Typecast(api_key="YOUR_API_KEY")response = ( client.compose_speech() .defaults(voice_id="tc_672c5f5ce59fac2a48faeaee", model="ssfm-v30") .say("Hello there") .pause(5) .say("Nice to meet you", voice_id="tc_60e5426de8b95f1d3000d7b5", output=Output(audio_pitch=2)) .say("Today") .pause(2) .say("How does the weather feel?") .generate())with open("conversation.wav", "wb") as f: f.write(response.audio_data)
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",))