使用 Voice Live API 的自備模型 (BYOM)

Voice Live API 提供自備模型 (BYOM) 功能,可讓您將自訂模型整合到語音互動工作流程中。 BYOM 適用於下列案例:

  • 微調模型:使用你的自訂 Azure OpenAI 或 Azure Foundry 模型
  • 任何未由 Voice Live 預先部署的 Foundry 模型:請使用 Foundry 模型目錄 中的模型,如 Anthropic Claude、Grok、 Fireworks 自訂權重,或模型 路由器 部署
  • 佈建輸送量:使用您的 PTU (佈建輸送量單位) 部署來取得一致的效能
  • 內容安全: 使用您的 LLM 應用定制的內容安全配置

這很重要

你可以將部署在 Azure Foundry 資源中的任何模型與 Voice Live API 整合。 若要使用來自其他 Foundry 資源的模型部署,請參見 資源覆寫

小提示

當您搭配 Voice Live 使用自己的模型部署時,建議您將其內容篩選設定設定為非 同步篩選 ,以減少延遲。 內容過濾設定可在 Microsoft Foundry 入口網站 中設定。

驗證設定

使用 Voice Live API 的 Microsoft Entra ID 認證時,在 byom-azure-openai-chat-completionbyom-foundry-anthropic-messages 模式下,你需要為 Foundry 資源設定適當的權限。 由於權杖會在長時間工作階段中過期,因此 Foundry 資源的系統指派受控識別,需要能存取這些 BYOM 模式的模型部署。

請執行以下 Azure CLI 指令來設定必要的權限:

export subscription_id=<your-subscription-id>
export resource_group=<your-resource-group>
export foundry_resource=<your-foundry-resource>

# Enable system-assigned managed identity for the foundry resource
az cognitiveservices account identity assign --name ${foundry_resource} --resource-group ${resource_group} --subscription ${subscription_id}

# Get the system-assigned managed identity object ID
identity_principal_id=$(az cognitiveservices account show --name ${foundry_resource} --resource-group ${resource_group} --subscription ${subscription_id} --query "identity.principalId" -o tsv)

# Assign the Foundry User role to the system identity of the foundry resource
az role assignment create --assignee-object-id ${identity_principal_id} --role "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" --scope /subscriptions/${subscription_id}/resourceGroups/${resource_group}/providers/Microsoft.CognitiveServices/accounts/${foundry_resource}

備註

由於 Foundry RBAC 角色最近被重新命名,請在程式碼中使用角色定義 ID(GUID)取代角色名稱,以避免在重新命名時出現問題:

  • Foundry 使用者53ca6127-db72-4b80-b1b0-d745d6d5456d
  • Foundry 擁有者c883944f-8b7b-4483-af10-35834be79c4a
  • Foundry 帳戶持有人e47c6f54-e4a2-4754-9501-8e0985b135e1
  • Foundry 專案管理者eadc314b-1a2d-4efa-be10-5d325db5065e

跨資源認證

當您使用資源覆寫時,無論您的驗證方式是 API 金鑰或 Microsoft Entra ID,都必須設有驗證設定。 您必須同時設定 Voice Live Foundry 資源與模型 Foundry 資源的權限。 執行以下指令來設定必要的權限:

export subscription_id_for_model=<your-subscription-id-for-model-resource>
export resource_group_for_model=<your-resource-group-for-model-resource>
export foundry_resource_for_model=<your-foundry-resource-for-model>

export subscription_id_for_voice_live=<your-subscription-id-for-voice-live-resource>
export resource_group_for_voice_live=<your-resource-group-for-voice-live-resource>
export foundry_resource_for_voice_live=<your-foundry-resource-for-voice-live>

# Enable system-assigned managed identity for the Voice Live Foundry resource
az cognitiveservices account identity assign \
    --name ${foundry_resource_for_voice_live} \
    --resource-group ${resource_group_for_voice_live} \
    --subscription ${subscription_id_for_voice_live}

# Get the system-assigned managed identity object ID
# for the Voice Live resource
identity_principal_id=$(az cognitiveservices account show \
    --name ${foundry_resource_for_voice_live} \
    --resource-group ${resource_group_for_voice_live} \
    --subscription ${subscription_id_for_voice_live} \
    --query "identity.principalId" -o tsv)

# Assign the Foundry User role to the Voice Live resource's
# system identity on the model Foundry resource
az role assignment create \
    --assignee-object-id ${identity_principal_id} \
    --role "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" \
    --scope /subscriptions/${subscription_id_for_model}/resourceGroups/${resource_group_for_model}/providers/Microsoft.CognitiveServices/accounts/${foundry_resource_for_model}

選擇 BYOM 整合模式

語音直播 API 支援三種 BYOM 整合模式:

Mode Description 範例模型
byom-azure-openai-realtime Azure OpenAI 即時語音互動模型用於串流語音互動 gpt-realtimegpt-realtime-mini
byom-azure-openai-chat-completion Azure OpenAI 聊天完成模型用於文字互動。 也適用於其他 Foundry 型號 gpt-5.4gpt-5.3-chatgrok-4
byom-foundry-anthropic-messages 在 Azure Foundry 中部署的 Anthropic Claude 模型,使用 Messages API(預覽版) claude-sonnet-4.6claude-haiku-4.5

備註

byom-foundry-anthropic-messages 模式目前仍在預覽階段。 預覽功能可能會有變動,且可用性可能有限。

整合 BYOM

更新 API 呼叫中的端點 URL,以包含您的 BYOM 設定:

wss://<your-foundry-resource>.services.ai.azure.com/voice-live/realtime?api-version=2026-04-10&profile=<your-byom-mode>&model=<your-model-deployment>

從 Foundry 門戶網站取得 <your-model-deployment> 值。 它對應於您在部署時為模型指定的名稱。

例如,要使用部署在 Azure Foundry 中的 Anthropic Claude 模型:

wss://<your-foundry-resource>.services.ai.azure.com/voice-live/realtime?api-version=2026-04-10&profile=byom-foundry-anthropic-messages&model=<your-claude-deployment-name>

若要從其他 Foundry 資源使用模型部署,請加入 foundry-resource-override 參數:

wss://<your-foundry-resource>.services.ai.azure.com/voice-live/realtime?api-version=2026-04-10&profile=<your-byom-mode>&model=<your-model-deployment>&foundry-resource-override=<foundry-resource>

這個 <foundry-resource> 值是沒有網域後綴的資源名稱。 例如,若 Foundry 資源端點為 https://my-foundry-resource.services.ai.azure.com,則使用 my-foundry-resource

備註

使用byom-foundry-anthropic-messages模式時,usage中的response.done事件欄位只包含語音標記用量(用於語音識別和文字轉語音)。 Anthropic 模型中的 LLM 代幣使用情況會分別在回應元資料中報告。

資源覆寫

預設情況下,Voice Live API 在與 Voice Live 服務相同的 Foundry 資源中使用 LLM 部署。 如果你的模型部署在不同的 Foundry 資源中,請指定 foundry-resource-override 查詢參數將 API 導向到正確的資源。 這支援跨區域情境,當語音直播服務與模型部署位於不同區域時。

這個 foundry-resource-override 值是沒有網域後綴的資源名稱。 例如,若 Foundry 資源端點為 https://my-foundry-resource.services.ai.azure.com,則使用 my-foundry-resource

請參閱 整合 BYOM 章節中的每個分頁以了解實作細節。

這很重要

使用資源覆寫時,無論你的認證方式(API 金鑰或 Microsoft Entra ID),都必須設定 跨資源認證