クイックスタート: Azure OpenAI の Whisper モデルを使った音声テキスト変換
このクイックスタートでは、音声テキスト変換に Azure OpenAI の Whisper モデルを使います。
Azure OpenAI の Whisper モデルには、25 MB というファイル サイズの制限があります。 25 MB を超えるファイルを文字起こしする必要がある場合は、Azure AI 音声のバッチ文字起こし API を使用できます。
前提条件
- Azure サブスクリプション。無料で作成できます。
- 目的の Azure サブスクリプション内の Azure OpenAI Service に付与されたアクセス。
- サポートされているリージョンに
whisper
モデルがデプロイされた Azure OpenAI リソース。 Whisper モデルのリージョン別の提供状況。 詳細については、「Azure OpenAI を使用してリソースを作成し、モデルをデプロイする」を参照してください。
Note
現在、Azure OpenAI Service にアクセスするには、アプリケーションを送信する必要があります。 アクセスを適用するには、こちらのフォームに入力してください。
設定
キーとエンドポイントを取得する
Azure OpenAI に対して正常に呼び出しを行うには、エンドポイントとキーが必要です。
変数名 | 値 |
---|---|
AZURE_OPENAI_ENDPOINT |
この値は、Azure portal からリソースを確認する際に、 [Keys & Endpoint](キーとエンドポイント) セクションで確認することができます。 Azure OpenAI Studio>[プレイグラウンド]>[コード ビュー] で値を確認することもできます。 エンドポイントの例: https://aoai-docs.openai.azure.com/ 。 |
AZURE_OPENAI_API_KEY |
この値は、Azure portal からリソースを確認する際に、 [Keys & Endpoint](キーとエンドポイント) セクションで確認することができます。 KEY1 または KEY2 を使用できます。 |
Azure portal でリソースに移動します。 [エンドポイントとキー] は [リソース管理] セクションにあります。 エンドポイントとアクセス キーをコピーします。これらは、API 呼び出しを認証するために両方とも必要です。 KEY1
または KEY2
を使用できます。 常に 2 つのキーを用意しておくと、サービスを中断させることなく、キーのローテーションと再生成を安全に行うことができます。
キーとエンドポイントの永続的な環境変数を作成して割り当てます。
環境変数
setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE"
setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE"
REST API
Bash シェルで、次のコマンドを実行します。 YourDeploymentName
は、Whisper モデルのデプロイ時に選んだデプロイ名に置き換える必要があります。 デプロイ名は必ずしもモデル名と同じではありません。 基になるモデル名と同じデプロイ名を選ばないと、モデル名の入力時にエラーが発生します。
curl $AZURE_OPENAI_ENDPOINT/openai/deployments/YourDeploymentName/audio/transcriptions?api-version=2024-02-01 \
-H "api-key: $AZURE_OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@./wikipediaOcelot.wav"
エンドポイントの例を含むコマンドの最初の行の形式は、次のようになります curl https://aoai-docs.openai.azure.com/openai/deployments/{YourDeploymentName}/audio/transcriptions?api-version=2024-02-01 \
。
GitHub の Azure AI 音声 SDK リポジトリからサンプル オーディオ ファイルを入手できます。
重要
運用環境では、Azure Key Vault などの資格情報を格納してアクセスする安全な方法を使用します。 資格情報のセキュリティについて詳しくは、Azure AI サービスのセキュリティに関する記事をご覧ください。
出力
{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
PowerShell
次のコマンドを実行します。 YourDeploymentName
は、Whisper モデルのデプロイ時に選んだデプロイ名に置き換える必要があります。 デプロイ名は必ずしもモデル名と同じではありません。 基になるモデル名と同じデプロイ名を選ばないと、モデル名の入力時にエラーが発生します。
# Azure OpenAI metadata variables
$openai = @{
api_key = $Env:AZURE_OPENAI_API_KEY
api_base = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
api_version = '2024-02-01' # this may change in the future
name = 'YourDeploymentName' #This will correspond to the custom name you chose for your deployment when you deployed a model.
}
# Header for authentication
$headers = [ordered]@{
'api-key' = $openai.api_key
}
$form = @{ file = get-item -path './wikipediaOcelot.wav' }
# Send a completion call to generate an answer
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/audio/transcriptions?api-version=$($openai.api_version)"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Form $form -Method Post -ContentType 'multipart/form-data'
return $response.text
GitHub の Azure AI 音声 SDK リポジトリからサンプル オーディオ ファイルを入手できます。
重要
運用環境では、Azure Key Valut を使用した PowerShell Secret Management のような安全な方法で認証情報を保存し、アクセスしてください。 資格情報のセキュリティについて詳しくは、Azure AI サービスのセキュリティに関する記事をご覧ください。
出力
The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs.
Python
前提条件
- Python 3.8 以降のバージョン
- 次の Python ライブラリ: os
設定
次を使用して、OpenAI Python クライアント ライブラリをインストールします。
pip install openai
quickstart.py という名前の新しい Python ファイルを作成します。 次に、任意のエディターまたは IDE で開きます。
quickstart.py の内容を次のコードに置き換えます。 コードを変更してデプロイ名を追加します。
import os
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-02-01",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
audio_test_file = "./wikipediaOcelot.wav"
result = client.audio.transcriptions.create(
file=open(audio_test_file, "rb"),
model=deployment_id
)
print(result)
クイック スタート ファイルで、 python コマンドを使用してアプリケーションを実行します。
GitHub の Azure AI 音声 SDK リポジトリからサンプル オーディオ ファイルを入手できます。
重要
運用環境では、Azure Key Vault などの資格情報を格納してアクセスする安全な方法を使用します。 資格情報のセキュリティについて詳しくは、Azure AI サービスのセキュリティに関する記事をご覧ください。
出力
{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
リソースをクリーンアップする
Azure OpenAI リソースをクリーンアップして削除したい場合は、リソースを削除できます。 リソースを削除する前に、まずデプロイされたモデルを削除する必要があります。
次のステップ
- Azure AI 音声のバッチ文字起こし API を使って Whisper モデルを操作する方法の詳細を参照してください。
- その他の例については、Azure OpenAI サンプルの GitHub リポジトリを参照してください
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示