轉錄語音

已完成

小提示

有關更多詳細信息,請參閱 文本和圖像 選項卡!

語音轉錄,或稱 語音轉文字,是指將音訊內容提交給模型,模型會回應以音訊來源中基於文字的語音文字轉錄。

支援語音轉文字操作的模型包括:

  • GPT-4O-轉錄
  • GPT-4O-MINI-轉錄
  • gpt-4o-transcribe-diarize

備註

模型可用性會依區域而有所不同。 請參考 Microsoft Foundry 文件中的 模型區域可用性 表。

使用語音轉文字模型

若要在自己的應用程式中使用語音轉文字模型,您可以使用 OpenAI SDK 中的 AzureOpenAI 用戶端,連接 Microsoft Foundry 資源的端點,並將音訊檔案內容上傳到模型進行轉錄。

from openai import AzureOpenAI
from pathlib import Path

# Create an AzureOpenAI client
client = AzureOpenAI(
    azure_endpoint=YOUR_FOUNDRY_ENDPOINT,
    api_key=YOUR_FOUNDRY_KEY,
    api_version="2025-03-01-preview"
)

# Get the audio file
file_path = Path("speech.mp3")
audio_file = open(file_path, "rb")

# Use the model to transcribe the audio file
transcription = client.audio.transcriptions.create(
    model=YOUR_MODEL_DEPLOYMENT,
    file=audio_file,
    response_format="text"
)

print(transcription)