> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cartesia.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 自動コミットによる ElevenLabs からの移行

このガイドでは、`commit_strategy=vad` で使用している ElevenLabs Realtime Speech to Text からの移行について説明します。

<Card horizontal title="すべての移行ガイド" icon="arrow-left-from-arc" href="/ja-jp/use-the-api/stt/migrations" />

このガイドには、素の API の説明と SDK コードの両方が含まれています。SDK をインストールするには次のようにします。

<CodeGroup>
  ```bash Python theme={null}
  pip install cartesia
  ```

  ```bash TypeScript theme={null}
  npm i @cartesia/cartesia-js
  ```
</CodeGroup>

<Info>
  すでに Cartesia SDK を使用している場合は、バージョン `>=3.2.0` にアップグレードしてください
</Info>

<Note>
  Ink 2 は現時点で英語のみをサポートしています。\
  今後数ヶ月のうちに他言語の追加を予定しています。
</Note>

## 接続

ElevenLabs の WebSocket URL と認証ヘッダーを、Cartesia の `/stt/turns/websocket` に置き換えます。

```diff theme={null}
- wss://api.elevenlabs.io/v1/speech-to-text/realtime?model_id=scribe_v2_realtime&audio_format=pcm_16000&commit_strategy=vad
+ wss://api.cartesia.ai/stt/turns/websocket?model=ink-2&encoding=pcm_s16le&sample_rate=16000
```

```diff theme={null}
- xi-api-key: <ELEVENLABS_API_KEY>
+ x-api-key: <CARTESIA_API_KEY>
+ cartesia-version: 2026-03-01
```

ブラウザでは、WebSocket はリクエストヘッダーをサポートしていません。代わりに、API バージョンを `cartesia_version` クエリパラメーターで渡し、API キーの代わりに短命の[アクセストークン](/get-started/authenticate-your-client-applications)を `access_token` クエリパラメーターで使用します。

Cartesia SDK を使って自動ファイナライズ WebSocket に接続します。

<CodeGroup>
  ```python Python theme={null}
  import os
  from cartesia import AsyncCartesia

  client = AsyncCartesia(api_key=os.getenv("CARTESIA_API_KEY"))

  async with client.stt.auto_finalize.websocket(
      model="ink-2", encoding="pcm_s16le", sample_rate=16000
  ) as connection:
      ...
  ```

  ```typescript TypeScript theme={null}
  import Cartesia from "@cartesia/cartesia-js";

  const client = new Cartesia({ apiKey: process.env.CARTESIA_API_KEY });

  const connection = client.stt.autoFinalize.websocket({
    model: "ink-2",
    encoding: "pcm_s16le",
    sample_rate: 16000,
  });
  ```

  ```typescript TypeScript (Browser) theme={null}
  // Server-side: Generate access-tokens using your API key
  import Cartesia from '@cartesia/cartesia-js';

  const client = new Cartesia({ apiKey: process.env.CARTESIA_API_KEY });

  export async function GET() {
    const { token } = await client.accessToken.create({
      grants: { stt: true, tts: false, agent: false },
      // How long the token lasts in seconds
      // Allowed values: 0–3600
      expires_in: 3600,
    });
    return Response.json({ token });
  }


  // Client-side
  // 1. Fetch an access token from your server
  // 2. Connect to Cartesia via WebSocket
  import Cartesia from "@cartesia/cartesia-js";

  async function getToken(): Promise<string> {
    const res = await fetch('/replace-with-your-server');
    const { token } = await res.json();
    return token;
  }
  const audioContext = new AudioContext();

  const client = new Cartesia({ token: await getToken() });

  const connection = client.stt.autoFinalize.websocket({
    model: "ink-2",
    encoding: "pcm_f32le",
    sample_rate: audioContext.sampleRate,
  });
  ```
</CodeGroup>

## クエリパラメーター

| ElevenLabs Scribe (VAD)                                                                         | Cartesia Realtime STT (Auto)                                                             | 備考                                                                                                        |
| ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `model_id=scribe_v2_realtime` <Badge color="red" size="sm">required</Badge>                     | `model=ink-2` <Badge color="red" size="sm">required</Badge>                              | すべてのオプションについては[モデル](/build-with-cartesia/stt/latest)を参照してください。                                            |
| `audio_format=pcm_16000`                                                                        | `encoding=pcm_s16le` + `sample_rate=16000` <Badge color="red" size="sm">required</Badge> | ElevenLabs はフォーマットとレートをまとめていますが、Cartesia はこれらを分離しています。[エンコーディング](#encoding)を参照してください。                     |
| `commit_strategy=vad`                                                                           | —                                                                                        | 手動コミットについては[手動ファイナライズ](/use-the-api/stt/migrate-from-elevenlabs-realtime-speech-to-text/manual)を参照してください。 |
| `language_code`                                                                                 | —                                                                                        | `ink-2` は現時点で `en` のみをサポートしています。より多くの言語が近日中に対応予定です。                                                       |
| —                                                                                               | `cartesia_version=2026-03-01` <Badge color="red" size="sm">required</Badge>              | 詳細については [API 規約](/use-the-api/api-conventions#always-send-a-cartesia-version-header)を参照してください。            |
| `vad_silence_threshold_secs`、`vad_threshold`、`min_speech_duration_ms`、`min_silence_duration_ms` | —                                                                                        | Cartesia は意味的なターン検出を使用します。VAD（音声区間検出）のチューニングは不要です。                                                        |
| `include_timestamps`                                                                            | —                                                                                        | 近日対応予定です。                                                                                                 |
| `keyterms`                                                                                      | `keyterm`                                                                                | 単数形の `keyterm` に注意してください。[キータームプロンプティング](/use-the-api/stt/keyterms)を参照してください。                             |
| `enable_logging`                                                                                | —                                                                                        | 組織によって制御されます。                                                                                             |

<Accordion title="encoding">
  ElevenLabs はサンプル形式とレートを 1 つの `audio_format` トークンにまとめています。Cartesia はこれらを `encoding` と `sample_rate` に分けています。

  | ElevenLabs `audio_format` | Cartesia `encoding` | Cartesia `sample_rate` |
  | ------------------------- | ------------------- | ---------------------- |
  | `pcm_8000`                | `pcm_s16le`         | `8000`                 |
  | `pcm_16000`               | `pcm_s16le`         | `16000`                |
  | `pcm_22050`               | `pcm_s16le`         | `22050`                |
  | `pcm_24000`               | `pcm_s16le`         | `24000`                |
  | `pcm_44100`               | `pcm_s16le`         | `44100`                |
  | `pcm_48000`               | `pcm_s16le`         | `48000`                |
  | `ulaw_8000`               | `pcm_mulaw`         | `8000`                 |

  Cartesia は `pcm_s32le`、`pcm_f16le`、`pcm_f32le`、`pcm_alaw` も受け付けます。\
  Cartesia のすべてのエンコーディングは、すべてのサンプルレートに対応しています。
</Accordion>

## 音声の送信

ElevenLabs は各音声チャンクを JSON 形式のテキストフレームでラップし、音声バイトを base64 エンコードします。\
Cartesia は音声チャンクをバイナリフレームとして受け取ります。生の音声バイトをそのまま送信します。

```diff theme={null}
- { "message_type": "input_audio_chunk", "audio_base_64": "<base64 PCM>", "commit": false, "sample_rate": 16000 }
+ <raw PCM bytes>
```

* 以前のテキストを渡す必要はありません
* サンプルレートは接続時に `sample_rate` クエリパラメーターによって決まります

<Warning>
  現在 ElevenLabs でセッションの途中で音声をコミットしている場合は、代わりに Cartesia の[手動ファイナライズ](./manual)の使用を検討してください。

  詳細については[移行ガイド](/use-the-api/stt/migrations)のページを参照してください。
</Warning>

すべての音声をコミットしてセッションを閉じるには、JSON 形式のテキストフレームを送信します。

```json theme={null}
{ "type": "close" }
```

Cartesia はバッファリングされたすべての音声を文字起こしした後、ソケットを閉じます。

### SDK による音声の送信

<CodeGroup>
  ```python Python theme={null}
  # ElevenLabs
  await elevenlabs_connection.send({
    "audio_base_64": b64encode(raw_audio),
  })

  # Cartesia
  # raw_audio (bytes) - Raw audio data, about 100 ms at a time
  await connection.send_raw(raw_audio)
  ```

  ```typescript TypeScript theme={null}
  // ElevenLabs
  elevenLabsConnection.send({ audioBase64: rawAudio.toBase64() });

  // Cartesia
  // @param {ArrayBufferLike} rawAudio - raw audio data, about 100 ms at a time
  connection.sendRaw(rawAudio);
  ```
</CodeGroup>

### 送信前に base64 エンコードされた音声をデコードする

<CodeGroup>
  ```python Python theme={null}
  # ElevenLabs
  await elevenlabs_connection.send({
    "audio_base_64": audio_base_64,
  })

  # Cartesia
  from base64 import b64decode
  await connection.send_raw(b64decode(audio_base_64))
  ```

  ```typescript TypeScript theme={null}
  // ElevenLabs
  elevenLabsConnection.send({ audioBase64 });

  // Cartesia
  connection.sendRaw(Uint8Array.fromBase64(audioBase64));
  ```
</CodeGroup>

### コミットとクローズ

<CodeGroup>
  ```python Python theme={null}
  # ElevenLabs
  elevenlabs_connection.on(RealtimeEvents.COMMITTED_TRANSCRIPT, lambda: elevenlabs_connection.close())
  await elevenlabs_connection.commit()

  # Cartesia
  await connection.send({"type": "close"})

  # Cartesia: Close the socket early (optional)
  await connection.close()
  ```

  ```typescript TypeScript theme={null}
  // ElevenLabs
  elevenLabsConnection.on(RealtimeEvents.COMMITTED_TRANSCRIPT, () => elevenLabsConnection.close());
  elevenLabsConnection.commit();

  // Cartesia
  connection.send({ type: "close" });

  // Cartesia: Close the socket early (optional)
  connection.close();
  ```
</CodeGroup>

## イベントのマッピング

Scribe は `partial_transcript` を発行し、その VAD がセグメントをコミットすると `committed_transcript` を発行します。

Cartesia は同じ情報をターンのライフサイクル（`turn.start`、`turn.update`、`turn.eager_end`、`turn.resume`、`turn.end`）にまとめています。完全なステートマシンについては[ターン検出](/use-the-api/stt/turns)を参照してください。

| ElevenLabs `message_type`              | Cartesia `type`  | 備考                                                                 |
| -------------------------------------- | ---------------- | ------------------------------------------------------------------ |
| `session_started`                      | `connected`      | 接続が確認されました。音声を送信する前にこれを待つ必要はありません。                                 |
| `partial_transcript`                   | `turn.update`    | ユーザーが発話している間の部分トランスクリプト。                                           |
| `committed_transcript`                 | `turn.end`       | ユーザーが発話を停止しました。ユーザーターンの完全なトランスクリプトを含みます。                           |
| `committed_transcript_with_timestamps` | `turn.end`       | タイムスタンプはまだ利用できません。                                                 |
| —                                      | `turn.start`     | ユーザーが話し始めました。トランスクリプトは含みません。                                       |
| —                                      | `turn.eager_end` | ユーザーが発話を終えた可能性があるとモデルが予測します。無視しても問題ありません。                          |
| —                                      | `turn.resume`    | ユーザーが話し続けました。直前の `turn.eager_end` は無視してください。                       |
| `error`                                | `error`          | クライアントエラーまたはサーバーエラー。                                               |
| `auth_error`                           | —                | Cartesia は WebSocket のアップグレードを 401 または 403 の HTTP ステータスで拒否します。     |
| `quota_exceeded`                       | `error`          | Cartesia のエラーレスポンスには `"error_code": "quota_exceeded"` が含まれます。      |
| `rate_limited`                         | `error`          | Cartesia のエラーレスポンスには `"error_code": "concurrency_limited"` が含まれます。 |
| `session_time_limit_exceeded`          | —                | Cartesia はコード `1001` の WebSocket クローズフレームを送信します。                   |

### 部分トランスクリプト

ElevenLabs の `partial_transcript`:

```json theme={null}
{
  "message_type": "partial_transcript",
  "text": "Hello"
}
```

は Cartesia の `turn.update` になります。

```json theme={null}
{
  "type": "turn.update",
  "transcript": "Hello",
  "request_id": "33cacee6-1936-4949-a05b-ecc9f2393248"
}
```

### コミット済みトランスクリプト

ElevenLabs の `committed_transcript`:

```json theme={null}
{
  "message_type": "committed_transcript",
  "text": "Hello world!"
}
```

は Cartesia の `turn.end` になります。

```json theme={null}
{
  "type": "turn.end",
  "transcript": "Hello world!",
  "request_id": "33cacee6-1936-4949-a05b-ecc9f2393248"
}
```

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from cartesia.types.stt import STTAutoFinalizeWebsocketResponse

  def on_message(message: STTAutoFinalizeWebsocketResponse) -> None:
      if message.type == "turn.start":
          print("User started speaking")
      elif message.type == "turn.update":
          print(f"partial_transcript: {message.transcript}")
      elif message.type == "turn.end":
          print(f"committed_transcript: {message.transcript}")
      elif message.type == "error":
          error_code = message.error_code or "unknown_error"
          if error_code == "quota_exceeded":
              print("You are out of credits")
          elif error_code == "concurrency_limited":
              print("You have too many open STT connections")
          else:
              print(f"{error_code}: {message.message}")

  connection.on("event", on_message)

  # ElevenLabs dispatches to your callbacks automatically;
  # with Cartesia you run the dispatch loop yourself
  recv_task = asyncio.create_task(connection.dispatch_events())
  ```

  ```typescript TypeScript theme={null}
  import Cartesia from '@cartesia/cartesia-js';

  connection.on("event", (message: Cartesia.STT.AutoFinalize.STTAutoFinalizeWebsocketResponse) => {
    switch (message.type) {
      case "turn.start":
        console.log("User started speaking");
        break;
      case "turn.update":
        console.log(`partial_transcript: ${message.transcript}`);
        break;
      case "turn.end":
        console.log(`committed_transcript: ${message.transcript}`);
        break;
    }
  });

  connection.on("error", (error) => {
    if (error.error) {
      // Server sent error (may be a bad request or internal server error)
      const errorCode = error.error.error_code || "unknown_error";
      switch (errorCode) {
        case "quota_exceeded":
          console.error("You are out of credits");
          break;
        case "concurrency_limited":
          console.error("You have too many open STT connections");
          break;
        default:
          console.error(`${errorCode}: ${error.error.message}`);
          break;
      }
    } else {
      // Client error
      console.error(`Client had an error: ${error.message}`);
    }
  });

  connection.on("close", (code: number, reason: string) => {
    if (code === 1001) {
      console.log("WebSocket closed due to inactivity");
    } else {
      console.log(`WebSocket closed (${code}): ${reason}`);
    }
  });
  ```
</CodeGroup>

## サーバーメッセージの例

> Scribe のトランスクリプトはスペースで結合されます。Ink のものは結合されません。

| ElevenLabs Scribe (VAD)                                                                                               | Cartesia Realtime STT (Auto)                                                               |
| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| —                                                                                                                     | <Badge>turn.start</Badge>                                                                  |
| <Badge color="orange">partial\_transcript</Badge> `"Scribe's transcripts"`                                            | <Badge color="orange">turn.update</Badge> `"Scribe's transcripts"`                         |
| —                                                                                                                     | <Badge>turn.eager\_end</Badge> `"Scribe's transcripts"`                                    |
| —                                                                                                                     | <Badge>turn.resume</Badge>                                                                 |
| <Badge color="orange">partial\_transcript</Badge> `"Scribe's transcripts are joined with spaces."`                    | <Badge color="orange">turn.update</Badge> `"Scribe's transcripts are joined with spaces."` |
| —                                                                                                                     | <Badge>turn.eager\_end</Badge> `"Scribe's transcripts are joined with spaces."`            |
| <Badge color="green">committed\_transcript</Badge> `"Scribe's transcripts are joined with spaces."`                   | <Badge color="green">turn.end</Badge> `"Scribe's transcripts are joined with spaces."`     |
| <Badge color="green">committed\_transcript\_with\_timestamps</Badge> `"Scribe's transcripts are joined with spaces."` | —                                                                                          |
| —                                                                                                                     | <Badge>turn.start</Badge>                                                                  |
| <Badge color="orange">partial\_transcript</Badge> `"Ink's are not."`                                                  | <Badge color="orange">turn.update</Badge> `" Ink's are not."`                              |
| —                                                                                                                     | <Badge>turn.eager\_end</Badge> `" Ink's are not."`                                         |
| <Badge color="green">committed\_transcript</Badge> `"Ink's are not."`                                                 | <Badge color="green">turn.end</Badge> `" Ink's are not."`                                  |
| <Badge color="green">committed\_transcript\_with\_timestamps</Badge> `"Ink's are not."`                               | —                                                                                          |

## リファレンス

<CardGroup cols={2}>
  <Card icon="code" title="API リファレンス" href="/api-reference/stt/turns/websocket">
    Cartesia Realtime STT (Auto)
  </Card>

  <Card icon="brackets-curly" title="完全なコード例" href="/examples/stt-auto-finalize-websocket">
    Cartesia SDK を使用する
  </Card>
</CardGroup>
