🎀 Channel TTS API β€” Quick Start

인증 ν† ν°μœΌλ‘œ batch / stream ν˜ΈμΆœν•˜λŠ” 방법

0. 토큰 μ€€λΉ„

λͺ¨λ“  TTS ν˜ΈμΆœμ€ /v1/external/text-to-speech/... κ²½λ‘œμ— Authorization: Bearer <token> 헀더λ₯Ό λΆ™μ—¬μ„œ μˆ˜ν–‰ν•©λ‹ˆλ‹€.

export CHTTS_API_KEY="<λ°œκΈ‰λ°›μ€ 토큰>"
토큰은 QWER Config의 secret κ°’μž…λ‹ˆλ‹€. μ €μž₯μ†Œ, μŠ¬λž™ 등에 ν‰λ¬ΈμœΌλ‘œ 남기지 λ§ˆμ„Έμš”.

1. Batch 호좜

전체 μ˜€λ””μ˜€λ₯Ό ν•œ λ²ˆμ— 생성해 WAV 파일둜 μ €μž₯ν•©λ‹ˆλ‹€.

curl -sS -X POST 'https://ch-tts-streaming-demo.channel.io/v1/external/text-to-speech/test-voice' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CHTTS_API_KEY" \
  -d '{"text":"μ•ˆλ…•ν•˜μ„Έμš”, μ±„λ„ν†‘μž…λ‹ˆλ‹€.","output_format":"wav_24000"}' \
  --output out.wav \
  -w '\nHTTP_STATUS:%{http_code}\n'

정상 응닡: 200 + out.wav (RIFF/WAVE, 24kHz mono)

둜컬 μž¬μƒ (macOS)

afplay out.wav

2. Stream 호좜

μ˜€λ””μ˜€ 청크λ₯Ό μ‹€μ‹œκ°„μœΌλ‘œ μŠ€νŠΈλ¦¬λ°ν•©λ‹ˆλ‹€. output_format은 pcm_*만 μ§€μ›ν•©λ‹ˆλ‹€ (슀트림 응닡은 wav_*λ₯Ό μ§€μ›ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€).

curl -sS -N -X POST 'https://ch-tts-streaming-demo.channel.io/v1/external/text-to-speech/test-voice/stream?optimize_streaming_latency=0' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CHTTS_API_KEY" \
  -d '{"text":"μ•ˆλ…•ν•˜μ„Έμš”, μ±„λ„ν†‘μž…λ‹ˆλ‹€.","output_format":"pcm_24000"}' \
  --output out.pcm \
  -w '\nHTTP_STATUS:%{http_code}\n'

정상 응닡: 200 + out.pcm (raw PCM16LE, mono, 24000Hz)

둜컬 μž¬μƒ (macOS) β€” PCM을 WAV둜 κ°μ‹Έμ„œ μž¬μƒ

python3 - <<'PY'
import wave
with open("out.pcm", "rb") as f:
    data = f.read()
with wave.open("out_from_stream.wav", "wb") as w:
    w.setnchannels(1)
    w.setsampwidth(2)
    w.setframerate(24000)
    w.writeframes(data)
PY
afplay out_from_stream.wav

ffplay둜 파일 μ €μž₯ 없이 λ°”λ‘œ μž¬μƒ

curl -sS -N -X POST 'https://ch-tts-streaming-demo.channel.io/v1/external/text-to-speech/test-voice/stream?optimize_streaming_latency=0' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CHTTS_API_KEY" \
  -d '{"text":"μ•ˆλ…•ν•˜μ„Έμš”, μ±„λ„ν†‘μž…λ‹ˆλ‹€.","output_format":"pcm_24000"}' \
| ffplay -nodisp -autoexit -f s16le -ar 24000 -ch_layout mono -i -

3. 인증 λ™μž‘ 확인 (선택)

토큰 κ²Œμ΄νŒ…μ΄ μ˜λ„λŒ€λ‘œ λ™μž‘ν•˜λŠ”μ§€ λΉ λ₯΄κ²Œ κ²€μ¦ν•˜κ³  싢을 λ•Œ:

μΌ€μ΄μŠ€κΈ°λŒ€ κ²°κ³Ό
external μ—”λ“œν¬μΈνŠΈ, 토큰 μ—†μŒ401
external μ—”λ“œν¬μΈνŠΈ, μ˜¬λ°”λ₯Έ 토큰 (batch)200
external μ—”λ“œν¬μΈνŠΈ, μ˜¬λ°”λ₯Έ 토큰 (stream)200
# external μ—”λ“œν¬μΈνŠΈ, 토큰 없이 -> 401
curl -sS -o /dev/null -X POST 'https://ch-tts-streaming-demo.channel.io/v1/external/text-to-speech/test-voice' \
  -H 'Content-Type: application/json' \
  -d '{"text":"test","output_format":"wav_24000"}' \
  -w 'HTTP_STATUS:%{http_code}\n'

# external μ—”λ“œν¬μΈνŠΈ, μ˜¬λ°”λ₯Έ 토큰 -> 200
curl -sS -o /dev/null -X POST 'https://ch-tts-streaming-demo.channel.io/v1/external/text-to-speech/test-voice' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CHTTS_API_KEY" \
  -d '{"text":"test","output_format":"wav_24000"}' \
  -w 'HTTP_STATUS:%{http_code}\n'

μ°Έκ³ 

Β· voice_idλŠ” ν˜„μž¬ λ¬΄μ‹œλ˜λ©° 값은 λ¬΄κ΄€ν•©λ‹ˆλ‹€ (μ˜ˆμ‹œμ—μ„œλŠ” test-voice μ‚¬μš©).

Β· /health, /ping은 인증 없이 항상 호좜 κ°€λŠ₯ν•©λ‹ˆλ‹€.

Β· μΈν„°λž™ν‹°λΈŒ API λ¬Έμ„œ(νŒŒλΌλ―Έν„°/μŠ€ν‚€λ§ˆ/Try it out)λŠ” Swagger UI λ˜λŠ” ReDocμ—μ„œ ν™•μΈν•˜μ„Έμš”.