타입캐스트 API를 위한 공식 Node.js 라이브러리입니다. AI 기반 음성을 사용하여 텍스트를 생동감 있는 음성으로 변환하세요.Javascript와 TypeScript 모두에서 작동합니다. 전체 TypeScript 타입이 포함되어 있습니다.ESM 및 CommonJS를 지원합니다. Node.js 18+ 및 최신 브라우저에서 작동합니다. Node.js 16/17 사용자는 isomorphic-fetch 폴리필을 설치해야 합니다.
최신 등록 버전은 npm 기준 0.4.7입니다. 버전 0.4.7 이상이 설치되어 있는지 확인하세요. npm list @neosapience/typecast-js로 버전을 확인할 수 있습니다. 이전 버전이 있다면 npm update @neosapience/typecast-js를 실행하여 업데이트하세요.
// 환경 변수 사용// export TYPECAST_API_KEY="your-api-key-here"const client = new TypecastClient({ apiKey: process.env.TYPECAST_API_KEY!});// 또는 직접 전달const client = new TypecastClient({ apiKey: 'your-api-key-here'});
자체 프록시를 통해 요청하는 경우 baseHost를 프록시 엔드포인트로 설정하고 apiKey를 생략할 수 있습니다. API 키가 비어 있거나 없으면 SDK는 X-API-KEY 헤더를 보내지 않습니다.
API 키 없는 프록시
const client = new TypecastClient({ baseHost: 'https://your-proxy.example.com'});
import { SmartPrompt } from '@neosapience/typecast-js';const audio = await client.textToSpeech({ text: "Everything is going to be okay.", voice_id: "tc_672c5f5ce59fac2a48faeaee", model: "ssfm-v30", prompt: { emotion_type: "smart", previous_text: "I just got the best news!", // 선택적 문맥 next_text: "I can't wait to celebrate!" // 선택적 문맥 } as SmartPrompt});
프리셋 값으로 감정을 명시적으로 설정합니다:
import { PresetPrompt } from '@neosapience/typecast-js';const audio = await client.textToSpeech({ text: "I am so excited to show you these features!", voice_id: "tc_672c5f5ce59fac2a48faeaee", model: "ssfm-v30", prompt: { emotion_type: "preset", emotion_preset: "happy", // normal, happy, sad, angry, whisper, toneup, tonedown emotion_intensity: 1.5 // 범위: 0.0 ~ 2.0 } as PresetPrompt});
오디오 데이터를 직접 다루지 않고 파일까지 바로 저장하려면 generateToFile을 사용하세요. 모델은 기본적으로 ssfm-v30을 사용하며, .mp3 / .wav 확장자는 output.audio_format이 없을 때 출력 포맷 추론에 사용됩니다. 사용할 보이스 ID는 Voices 페이지에서 확인할 수 있습니다.
await client.generateToFile('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 함수를 호출하지 않아도 텍스트만 보고 쉼 위치를 확인할 수 있습니다.
const audio = await client .composeSpeech() .defaults({ voice_id: 'tc_672c5f5ce59fac2a48faeaee', model: 'ssfm-v30' }) .say('안녕하세요<|5s|>반갑습니다<|1s|>오늘<|2s|>날씨는 어떤 것 같으세요?') .generate();
한 파일 안에서 서로 다른 voice나 구간별 pitch, tempo, prompt, seed 같은 옵션을 조합해야 할 때 사용합니다. composer는 각 구간을 WAV로 생성하고 앞뒤 무음 PCM 샘플을 trim한 뒤 합성합니다. MP3가 필요하면 먼저 WAV를 생성한 다음 앱 또는 서버 파이프라인에서 변환하세요.
import { TypecastClient } from '@neosapience/typecast-js';import fs from 'fs/promises';const client = new TypecastClient({ apiKey: 'YOUR_API_KEY' });const audio = await client .composeSpeech() .defaults({ voice_id: 'tc_672c5f5ce59fac2a48faeaee', model: 'ssfm-v30' }) .say('Hello there') .pause(5) .say('Nice to meet you', { voice_id: 'tc_60e5426de8b95f1d3000d7b5', output: { audio_pitch: 2 } }) .say('Today') .pause(2) .say('How does the weather feel?') .generate();await fs.writeFile('conversation.wav', Buffer.from(audio.audioData));