若要使用 sunra API 將語音轉換為文字,您需要傳送一個請求至適當的端點,並附上必要的輸入參數。該 API 利用預先訓練的模型將音訊檔案轉錄為文字,只需提供一個音訊檔案即可實現無縫轉換。 以下是如何使用 sunra API 進行語音轉文字轉換的範例:
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);

選擇正確的模型

sunra 提供一系列語音轉文字模型以滿足不同需求。根據您對準確性和效能的要求選擇模型。 以下是一些可用選項:
  • elevenlabs/scribe-v1:支援 99 種語言的語音轉文字,具有單詞級時間戳和說話人分段功能——是該公司迄今最準確的 ASR。
若要使用特定模型,請在 subscribe 方法中指定其 ID,如範例所示。如需更多模型和詳細資訊,請造訪 語音轉文字模型 頁面。