오디오 음성 엔드포인트

오디오 음성 엔드포인트 (Audio Speech Endpoints)

텍스트로부터 음성을 생성하는 API입니다. 말할 내용과 목소리를 넣으면 오디오 데이터로 바꿔줘요.

출처: 문서

본문

음성 합성(Text-to-Speech)용 엔드포인트예요. 원하는 문장과 목소리, 응답 포맷 등을 지정해서 음성 오디오를 생성합니다.

POST /v1/audio/speech — Speech (음성 생성)

텍스트를 음성으로 변환합니다.

요청 본문:

  • input#string (필수) — 음성으로 만들 텍스트.
  • model#string|null — 사용할 모델.
  • voice_id#string|null — 음성 생성에 쓸 프리셋 또는 커스텀 목소리.
  • ref_audio#string|null — 음성 생성에 활용할 오디오 참조.
  • response_format#"pcm"|"wav"|"mp3"|"flac"|"opus" — 응답 오디오 포맷.
  • stream#boolean — 기본값 false. 스트리밍 여부.
  • prompt_cache_key#string|null — 프롬프트 캐시 키.
  • metadata#map<any>|null — 메타데이터.
  • AdditionalProperties#map<any> — 추가 속성.

응답:

  • 200 (application/json) — 다음 형태의 음성 오디오 데이터를 반환합니다.
    • audio_data#string (필수) — Base64로 인코딩된 오디오 데이터.
  • 200 (text/event-stream) — event-stream<SpeechStreamEvents> 타입.
    • SpeechStreamEvents — {object}
    • audio_data#string (필수) — Base64로 인코딩된 오디오 데이터.

TypeScript:

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: proces...EY"] ?? "",
});

async function run() {
  const result = await mistral.audio.speech.complete({
    input: "<value>",
  });

  console.log(result);
}

run();

Python:

from mistralai.client import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.audio.speech.complete(input="<value>", stream=False, additional_properties={

    })

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

curl:

curl https://api.mistral.ai/v1/audio/speech \
 -X POST \
 -H 'Authorization: Bearer ***' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": "Example input."
}'

응답 예시 (200, application/json):

{
  "audio_data": "base64-encoded-audio-data"
}

더 알아보기 (Learn more)