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

# 語音轉文字

若要使用 sunra API 將語音轉換為文字，您需要傳送一個請求至適當的端點，並附上必要的輸入參數。該 API 利用預先訓練的模型將音訊檔案轉錄為文字，只需提供一個音訊檔案即可實現無縫轉換。

以下是如何使用 sunra API 進行語音轉文字轉換的範例：

<CodeGroup>
  ```javascript Javascript theme={null}
  import { sunra } from "@sunra/client";

  const result = await sunra.subscribe("elevenlabs/scribe-v1/speech-to-text", {
    input: {
      audio: 'https://assets.sunra.ai/uploads/1749243418768-74d68e25.wav',
      language: 'English',
      tag_audio_events: true,
      speaker_diarization: false
    },
    logs: true,
    onQueueUpdate: (update) => {
      console.log(update)
    },
  });
  console.log(result.data);
  console.log(result.requestId);
  ```

  ```python Python theme={null}
  import sunra_client

  result = sunra_client.subscribe(
      "elevenlabs/scribe-v1/speech-to-text",
      arguments={
          "audio": "https://assets.sunra.ai/uploads/1749243418768-74d68e25.wav",
          "language": "English",
          "tag_audio_events": True,
          "speaker_diarization": False
      },
      with_logs=True,
      on_enqueue=print,
      on_queue_update=print,
  )
  print(result) 
  ```

  ```java Java theme={null}
  import ai.sunra.client.*;
  import java.util.Map;
  import com.google.gson.JsonObject;

  var client = SunraClient.withEnvCredentials();

  var response = client.subscribe(
      "elevenlabs/scribe-v1/speech-to-text",
      SubscribeOptions.<JsonObject>builder()
          .input(Map.of(
              "audio", "https://assets.sunra.ai/uploads/1749243418768-74d68e25.wav",
              "language", "English",
              "tag_audio_events", true,
              "speaker_diarization", false))
          .resultType(JsonObject.class)
          .onQueueUpdate(update -> System.out.printf(
              "\n狀態更新：%s，請求 ID：%s%n",
              update.getStatus(),
              update.getRequestId()
          ))
          .logs(true)
          .build()
  );

  System.out.println("已完成！");
  System.out.println(response.getData());
  ```

  ```bash Curl theme={null}
  curl --request POST \
    --url https://api.sunra.ai/v1/queue/elevenlabs/scribe-v1/speech-to-text \
    --header "Authorization: Key $SUNRA_KEY" \
    --header "Content-Type: application/json" \
    --data '{"audio":"https://assets.sunra.ai/uploads/1749243418768-74d68e25.wav","language":"English","tag_audio_events":true,"speaker_diarization":false}'

  ```
</CodeGroup>

### 選擇正確的模型

sunra 提供一系列語音轉文字模型以滿足不同需求。根據您對準確性和效能的要求選擇模型。

以下是一些可用選項：

* **[elevenlabs/scribe-v1](https://sunra.ai/models/elevenlabs/scribe-v1)**：支援 99 種語言的語音轉文字，具有單詞級時間戳和說話人分段功能——是該公司迄今最準確的 ASR。

若要使用特定模型，請在 `subscribe` 方法中指定其 ID，如範例所示。如需更多模型和詳細資訊，請造訪 [語音轉文字模型](https://sunra.ai/models?modalities%5B0%5D=modality-audio-text) 頁面。
