次の方法で共有


Azure AI Speech Transcription client library for JavaScript - バージョン 1.0.0-beta.1

Azure AI音声文字起こしクライアントライブラリは、音声をテキストに高精度で変換するAzureの音声変換サービスに簡単にアクセスできるよう支援します。

クライアント ライブラリを使用して、次の手順を実行します。

  • 音声ファイルをテキストに書き起こし
  • 複数の言語と地域に対応しています
  • 異なるスピーカーを識別するためのスピーカーダイアライゼーションを有効にします
  • 罵り言葉のフィルタリングを適用してください
  • カスタム音声モデルの使用
  • ローカルファイルとリモートURLの両方を処理します
  • LLM搭載の文字起こしと翻訳にはエンハンストモードを使用

主要なリンク:

作業の開始

現在サポートされている環境

詳細については、サポート ポリシーの を参照してください。

前提条件

@azure/ai-speech-transcription パッケージをインストールする

JavaScript用のAzure AI音声文字起こしクライアントライブラリを npmインストールしてください:

npm install @azure/ai-speech-transcription

TranscriptionClient を作成して認証する

Azure Transcription APIにアクセスするクライアントオブジェクトを作成するには、Azure Transcriptionリソースの endpointcredentialが必要です。 Azure Transcription リソースのエンドポイントは Azure Portalで見つけることができます。

オプション1:APIキー認証

SpeechリソースのAPIキーは Azureポータルで見つけることができます。

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));

本番環境では、管理されたIDやサービスプリンシパルを用いたEntra ID認証の使用が推奨されます。 @azure/identity パッケージのインストール:

npm install @azure/identity

また、管理型アイデンティティやサービスプリンシパルに適切な役割(例:「認知サービスユーザー」)を割り当てる必要があります。 詳細については、 Azure AI Services認証をご覧ください。

Node.js とノードに似た環境を使用すると、DefaultAzureCredential クラスを使用してクライアントを認証できます。

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { DefaultAzureCredential } from "@azure/identity";

const client = new TranscriptionClient("<endpoint>", new DefaultAzureCredential());

ブラウザー環境では、InteractiveBrowserCredential パッケージの @azure/identity を使用して認証します。

import { InteractiveBrowserCredential } from "@azure/identity";
import { TranscriptionClient } from "@azure/ai-speech-transcription";

const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const client = new TranscriptionClient("<endpoint>", credential);

サービス API のバージョン

クライアントライブラリはデフォルトで最新のサービスAPIバージョンをターゲットにしています。 クライアントをインスタンス化する際に、特定の対応APIバージョンを選択できます:

import { TranscriptionClient, KnownServiceApiVersions } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"), {
  serviceVersion: KnownServiceApiVersions.V20251015,
});

JavaScript バンドル

ブラウザーでこのクライアント ライブラリを使用するには、まず、バンドルを使用する必要があります。 これを行う方法の詳細については、バンドルドキュメントを参照してください。

主な概念

トランスクリプトクライアント

TranscriptionClient はAzure AI音声文字起こしクライアントライブラリを使用する開発者向けの主要なインターフェースです。 この方法は、音声バイナリデータ用と音声URL用という2つのオーバーロードされた transcribe 方式を提供します。

オーディオ形式

このサービスはWAV、MP3、OGG、FLACなど様々な音声フォーマットをサポートしています。 音声は以下のものでなければなりません:

  • 2時間未満の時間
  • 250MB未満のサイズ

文字起こしオプション

以下のようなオプションで文字起こしをカスタマイズできます:

  • 罵り言葉フィルタリング:文字起こし("None""Masked""Removed""Tags")における罵り言葉の扱いを制御する
  • スピーカーのディアライゼーション:マルチスピーカー音声(最大36スピーカー)で異なるスピーカーを識別する
  • フレーズリスト:正確性を高めるためにドメイン固有のフレーズを提供しましょう
  • 言語検出:話されている言語を自動的に検出するか、既知の位置を指定する
  • 強化モード:LLM搭載の処理、翻訳、プロンプトベースのカスタマイズで文字起こしの品質を向上させる

例示

ローカルオーディオファイルを文字起こしする

最も基本的な操作は、ローカルファイルシステムから音声ファイルを文字起こしすることです:

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.wav");
const result = await client.transcribe(audioFile);
console.log(`Duration: ${result.durationInMs}ms`);
console.log("Transcription:", result.combinedPhrases[0]?.text);

URLから音声を書き起こし

ファイルをダウンロードせずに、公開されているURLから直接音声を文字起こしできます:

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const result = await client.transcribe("https://example.com/audio/sample.wav", {
  locales: ["en-US"],
});
console.log("Transcription:", result.combinedPhrases[0]?.text);

個々の文字起こし単語へのアクセス

タイムスタンプ、信頼度スコア、単語ごとの単語レベル詳細にアクセスするには:

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.wav");
const result = await client.transcribe(audioFile);
for (const phrase of result.phrases) {
  console.log(`Phrase: ${phrase.text}`);
  console.log(
    `  Offset: ${phrase.offsetMilliseconds}ms | Duration: ${phrase.durationMilliseconds}ms`,
  );
  console.log(`  Confidence: ${phrase.confidence.toFixed(2)}`);
  // Access individual words in the phrase
  for (const word of phrase.words ?? []) {
    console.log(`    Word: '${word.text}' | Offset: ${word.offsetMilliseconds}ms`);
  }
}

発言者をダイアライズ(日記付き)で識別する

話者日誌は、複数話者による会話で誰が話したかを特定することです:

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/conversation.wav");
const result = await client.transcribe(audioFile, {
  diarizationOptions: {
    maxSpeakers: 4, // Expect up to 4 speakers in the conversation
  },
});
for (const phrase of result.phrases) {
  console.log(`Speaker ${phrase.speaker}: ${phrase.text}`);
}

注:特定された話者の総数は決して maxSpeakersを超えることはありません。 実際の音声に指定以上のスピーカーが含まれている場合、サービス側はそれらを統合します。 正確な数がわからない場合は、合理的な上限を設定しましょう。

フィルターの罵り言葉

異なるフィルターモードを使って、書き起こしにおける罵り言葉の出現方法をコントロールしてください:

import { TranscriptionClient, KnownProfanityFilterModes } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.wav");
const result = await client.transcribe(audioFile, {
  profanityFilterMode: KnownProfanityFilterModes.Masked, // Default - profanity replaced with asterisks
});
console.log("Transcription:", result.combinedPhrases[0]?.text);

利用可能なモード:

  • "None": フィルターなし — 罵り言葉は話されたものと同じように現れます
  • "Masked": 罵り言葉はアスタリスクに置き換えられています(例: f***)
  • "Removed": テキストから完全に下品な言葉を削除しました
  • "Tags":XMLタグで囲まれた罵り言葉(例: <profanity>word</profanity>)

カスタムフレーズで精度を高める

ドメイン固有の用語、名称、略語を正しく認識できるカスタムフレーズを追加してください:

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.wav");
const result = await client.transcribe(audioFile, {
  phraseList: {
    phrases: ["Contoso", "Jessie", "Rehaan"],
  },
});
console.log("Transcription:", result.combinedPhrases[0]?.text);

既知の言語で書き起こしてください

音声の言語が分かれば、単一のロケーションを指定することで精度が向上し、遅延も低減されます。

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/english-audio.mp3");
const result = await client.transcribe(audioFile, {
  locales: ["en-US"],
});
console.log("Transcription:", result.combinedPhrases[0]?.text);

言語が不明な場合の言語識別では、複数の候補地点を指定すると、サービスが自動的に言語を検出します。

import { TranscriptionClient } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.mp3");
const result = await client.transcribe(audioFile, {
  locales: ["en-US", "es-ES"],
});
for (const phrase of result.phrases) {
  console.log(`[${phrase.locale}] ${phrase.text}`);
}

最高精度を狙うにはエンハンストモードを使用してください

Enhanced Modeは、最高精度の転記のためにLLM駆動の処理を使用しています:

import { TranscriptionClient, KnownProfanityFilterModes } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/audio.wav");
const result = await client.transcribe(audioFile, {
  // Enhanced mode: LLM-powered speech recognition with prompt customization
  enhancedMode: {
    task: "transcribe",
    prompt: ["Output must be in lexical format."],
  },
  // Existing Fast Transcription options work alongside enhanced mode
  diarizationOptions: {
    maxSpeakers: 2,
  },
  profanityFilterMode: KnownProfanityFilterModes.Masked,
  activeChannels: [0, 1],
});
for (const phrase of result.phrases) {
  console.log(`[Speaker ${phrase.speaker}] ${phrase.text}`);
}

エンハンストモードで翻訳

エンハンストモードは音声を目標言語に翻訳することもサポートしています:

import { TranscriptionClient, KnownProfanityFilterModes } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/chinese-audio.wav");
const result = await client.transcribe(audioFile, {
  enhancedMode: {
    task: "translate",
    targetLanguage: "ko", // Translate to Korean
  },
  profanityFilterMode: KnownProfanityFilterModes.Masked,
});
console.log("Translated to Korean:", result.combinedPhrases[0]?.text);

複数の選択肢を組み合わせる

複雑なシナリオでは複数の転写機能を組み合わせることができます:

import { TranscriptionClient, KnownProfanityFilterModes } from "@azure/ai-speech-transcription";
import { AzureKeyCredential } from "@azure/core-auth";
import { readFileSync } from "node:fs";

const client = new TranscriptionClient("<endpoint>", new AzureKeyCredential("<api-key>"));
const audioFile = readFileSync("path/to/meeting.wav");
const result = await client.transcribe(audioFile, {
  // Enable speaker diarization
  diarizationOptions: {
    maxSpeakers: 5,
  },
  // Mask profanity
  profanityFilterMode: KnownProfanityFilterModes.Masked,
  // Add custom phrases
  phraseList: {
    phrases: ["action items", "Q4", "KPIs"],
  },
});
console.log("Full Transcript:");
console.log(result.combinedPhrases[0]?.text);
for (const phrase of result.phrases) {
  console.log(`Speaker ${phrase.speaker}: ${phrase.text}`);
}

Troubleshooting

一般的な問題

  • 認証失敗:APIキーやEntra IDの認証情報が正しく、Speechリソースがアクティブかどうかを必ず確認してください。
  • サポートされていない音声フォーマット:音声がサポートされているフォーマット(WAV、MP3、OGG、FLACなど)であることを確認しましょう。 サービスは自動的にフォーマット検出を処理します。
  • ゆっくりとした文字起こし:大きなファイルの場合はネットワーク接続が安定していることを確認してください。
  • 精度の低下:正しいロケーションを指定する、ドメイン固有の用語にカスタムフレーズを追加する、またはエンハンストモードを使うことを試してみてください。

ログ記録

ログ記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、AZURE_LOG_LEVEL 環境変数を infoに設定します。 または、setLogLevel@azure/logger を呼び出すことによって、実行時にログを有効にすることもできます。

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

ログを有効にする方法の詳細な手順については、 @azure/logger パッケージのドキュメントを参照してください。

次のステップ

高度な機能についてさらに詳しく知るために、さらなるサンプルをご覧ください:

Contributing

このライブラリに投稿する場合は、コードをビルドしてテストする方法の詳細については、投稿ガイド を参照してください。

  • Microsoft Azure SDK for JavaScript の