部署自定义语音模型

本文介绍如何为自定义语音模型部署终结点。 除了批量听录之外,还必须部署自定义终结点才能使用自定义语音模型。

提示

无需托管部署终结点即可将自定义语音识别与批量听录 API 配合使用。 如果自定义语音模型仅用于批量听录,则可以节省资源。 有关详细信息,请参阅语音服务定价

可以为基本模型或自定义模型部署终结点,然后更新终结点,以便使用更好的训练模型。

注意

F0 语音资源使用的终结点在 7 天后删除。

添加部署终结点

若要创建自定义终结点,请执行以下步骤:

  1. 登录 Speech Studio

  2. 选择“自定义语音识别”> 你的项目名称 >“部署模型”。

    如果这是你的第一个终结点,你会注意到表中未列出任何终结点。 创建一个终结点后,即可使用此页面跟踪每个已部署的终结点。

  3. 选择“部署模型”以启动新的终结点向导。

  4. 在“新建终结点”页上,输入自定义终结点的名称和说明。

  5. 选择要与终结点关联的自定义模型。

  6. (可选)可以选中该框以启用终结点流量的音频和诊断日志记录

    该屏幕截图显示了新建终结点页面,其中显示启用日志记录的复选框。

  7. 选择“添加”以保存并部署终结点。

在主“部署模型”页上,有关新终结点的详细信息(例如名称、说明、状态和到期日期)将显示在表中。 使用自定义模型实例化新终结点最长可能需要 30 分钟才能完成。 当部署状态更改为“成功”时,终结点便可供使用。

重要

记下模型到期日期。 这是可以使用自定义模型进行语音识别的最后日期。 有关详细信息,请参阅模型和终结点生命周期

选择此终结点链接可查看特定于该终结点的信息,例如终结点密钥、终结点 URL 和示例代码。

若要创建终结点并部署模型,请使用 spx csr endpoint create 命令。 根据以下说明构造请求参数:

  • project 参数设置为现有项目的 ID。 建议这样做,以便还可以在 Speech Studio 中查看和管理终结点。 可以运行 spx csr project list 命令来获取可用项目。
  • 将所需的 model 参数设置为要部署到终结点的模型的 ID。
  • 设置所需的 language 参数。 终结点区域设置必须与模型区域设置相匹配。 以后无法更改区域设置。 语音 CLI language 参数对应于 JSON 请求和响应中的 locale 属性。
  • 设置所需的 name 参数。 这是 Speech Studio 中显示的名称。 语音 CLI name 参数对应于 JSON 请求和响应中的 displayName 属性。
  • (可选)可设置 logging 参数。 将其设置为 enabled,以启用终结点流量的音频和诊断日志记录。 默认为 false

下面是用于创建终结点和部署模型的语音 CLI 命令示例:

spx csr endpoint create --api-version v3.1 --project YourProjectId --model YourModelId --name "My Endpoint" --description "My Endpoint Description" --language "en-US"

你应该会收到以下格式的响应正文:

{
  "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/base/ae8d1643-53e4-4554-be4c-221dcfb471c5"
  },
  "links": {
    "logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790/files/logs",
    "restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790"
  },
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/d40f2eb8-1abf-4f72-9008-a5ae8add82a4"
  },
  "properties": {
    "loggingEnabled": true
  },
  "lastActionDateTime": "2022-05-19T15:27:51Z",
  "status": "NotStarted",
  "createdDateTime": "2022-05-19T15:27:51Z",
  "locale": "en-US",
  "displayName": "My Endpoint",
  "description": "My Endpoint Description"
}

响应正文中的顶级 self 属性是终结点的 URI。 使用此 URI 可获取有关终结点项目、模型和日志的详细信息。 还可以使用此 URI 更新终结点。

有关终结点的语音 CLI 帮助,请运行以下命令:

spx help csr endpoint

若要创建终结点并部署模型,请使用语音转文本 REST APIEndpoints_Create 操作。 根据以下说明构造请求正文:

  • project 属性设置为现有项目的 URI。 建议这样做,以便还可以在 Speech Studio 中查看和管理终结点。 可以发出 Projects_List 请求来获取可用项目。
  • 将所需的 model 属性设置为要部署到终结点的模型的 URI。
  • 设置所需的 locale 属性。 终结点区域设置必须与模型区域设置相匹配。 以后无法更改区域设置。
  • 设置所需的 displayName 属性。 这是 Speech Studio 中显示的名称。
  • (可选)可在 properties 中设置 loggingEnabled 属性。 将其设置为 true,以启用终结点流量的音频和诊断日志记录。 默认为 false

使用 URI 发出 HTTP POST 请求,如以下 Endpoints_Create 示例所示。 将 YourSubscriptionKey 替换为语音资源密钥,将 YourServiceRegion 替换为语音资源区域,并按前面所述设置请求正文属性。

curl -v -X POST -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey" -H "Content-Type: application/json" -d '{
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/d40f2eb8-1abf-4f72-9008-a5ae8add82a4"
  },
  "properties": {
    "loggingEnabled": true
  },
  "displayName": "My Endpoint",
  "description": "My Endpoint Description",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/base/ae8d1643-53e4-4554-be4c-221dcfb471c5"
  },
  "locale": "en-US",
}'  "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.1/endpoints"

你应该会收到以下格式的响应正文:

{
  "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/base/ae8d1643-53e4-4554-be4c-221dcfb471c5"
  },
  "links": {
    "logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790/files/logs",
    "restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790"
  },
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/d40f2eb8-1abf-4f72-9008-a5ae8add82a4"
  },
  "properties": {
    "loggingEnabled": true
  },
  "lastActionDateTime": "2022-05-19T15:27:51Z",
  "status": "NotStarted",
  "createdDateTime": "2022-05-19T15:27:51Z",
  "locale": "en-US",
  "displayName": "My Endpoint",
  "description": "My Endpoint Description"
}

响应正文中的顶级 self 属性是终结点的 URI。 使用此 URI 可获取终结点项目、模型和日志的详细信息。 还可以使用此 URI 更新删除终结点。

更改模型和重新部署终结点

可以更新终结点,以使用由同一语音资源创建的另一个模型。 如前所述,必须在模型过期之前更新终结点的模型。

若要使用新模型并重新部署自定义终结点,请执行以下操作:

  1. 登录 Speech Studio
  2. 选择“自定义语音识别”> 你的项目名称 >“部署模型”。
  3. 按名称选择指向终结点的链接,然后选择“更改模型”。
  4. 选择你希望终结点使用的新模型。
  5. 选择“完成”以保存并重新部署终结点。

若要使用新模型重新部署自定义终结点,请使用 spx csr model update 命令。 根据以下说明构造请求参数:

  • 将所需的 endpoint 参数设置为要部署的终结点的 ID。
  • 将所需的 model 参数设置为要部署到终结点的模型的 ID。

以下是使用新模型重新部署自定义终结点的示例语音 CLI 命令:

spx csr endpoint update --api-version v3.1 --endpoint YourEndpointId --model YourModelId

你应该会收到以下格式的响应正文:

{
  "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/1e47c19d-12ca-4ba5-b177-9e04bd72cf98"
  },
  "links": {
    "logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790/files/logs",
    "restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790"
  },
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/639d5280-8995-40cc-9329-051fd0fddd46"
  },
  "properties": {
    "loggingEnabled": true
  },
  "lastActionDateTime": "2022-05-19T23:01:34Z",
  "status": "NotStarted",
  "createdDateTime": "2022-05-19T15:41:27Z",
  "locale": "en-US",
  "displayName": "My Endpoint",
  "description": "My Updated Endpoint Description"
}

有关终结点的语音 CLI 帮助,请运行以下命令:

spx help csr endpoint

若要使用新模型重新部署自定义终结点,请使用语音转文本 REST APIEndpoints_Update 操作。 根据以下说明构造请求正文:

  • model 属性设置为要部署到终结点的模型的 URI。

使用 URI 发出 HTTP PATCH 请求,如以下示例所示。 将 YourSubscriptionKey 替换为语音资源密钥,将 YourServiceRegion 替换为语音资源区域,将 YourEndpointId 替换为终结点 ID,并按前面所述设置请求正文属性。

curl -v -X PATCH -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey" -H "Content-Type: application/json" -d '{
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/1e47c19d-12ca-4ba5-b177-9e04bd72cf98"
  }
}'  "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/YourEndpointId"

你应该会收到以下格式的响应正文:

{
  "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/1e47c19d-12ca-4ba5-b177-9e04bd72cf98"
  },
  "links": {
    "logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790/files/logs",
    "restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790"
  },
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/639d5280-8995-40cc-9329-051fd0fddd46"
  },
  "properties": {
    "loggingEnabled": true
  },
  "lastActionDateTime": "2022-05-19T23:01:34Z",
  "status": "NotStarted",
  "createdDateTime": "2022-05-19T15:41:27Z",
  "locale": "en-US",
  "displayName": "My Endpoint",
  "description": "My Updated Endpoint Description"
}

重新部署需要数分钟才能完成。 同时,终结点将使用以前的模型,而不会中断服务。

查看日志记录数据

如果在创建终结点时配置了日志记录数据,则可以导出该数据。

若要下载终结点日志,请执行以下操作:

  1. 登录 Speech Studio
  2. 选择“自定义语音识别”> 你的项目名称 >“部署模型”。
  3. 按终结点名称选择链接。
  4. 在“内容日志记录”下,选择“下载日志”。

若要获取终结点的日志,请使用 spx csr endpoint list 命令。 根据以下说明构造请求参数:

  • 将所需的 endpoint 参数设置为要获取日志的终结点的 ID。

以下是获取终结点日志的示例语音 CLI 命令:

spx csr endpoint list --api-version v3.1 --endpoint YourEndpointId

每个日志文件的位置(其中包含更多详细信息)将在响应正文中返回。

若要获取终结点日志,请先使用语音转文本 REST APIEndpoints_Get 操作。

使用 URI 提出 HTTP GET 请求,如以下示例所示。 将 YourEndpointId 替换为终结点 ID,将 YourSubscriptionKey 替换为语音资源密钥,将 YourServiceRegion 替换为语音资源区域。

curl -v -X GET "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/YourEndpointId" -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey"

你应该会收到以下格式的响应正文:

{
  "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790",
  "model": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/models/1e47c19d-12ca-4ba5-b177-9e04bd72cf98"
  },
  "links": {
    "logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/98375aaa-40c2-42c4-b65c-f76734fc7790/files/logs",
    "restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790",
    "webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=98375aaa-40c2-42c4-b65c-f76734fc7790"
  },
  "project": {
    "self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.1/projects/2f78cdb7-58ac-4bd9-9bc6-170e31483b26"
  },
  "properties": {
    "loggingEnabled": true
  },
  "lastActionDateTime": "2022-05-19T23:41:05Z",
  "status": "Succeeded",
  "createdDateTime": "2022-05-19T23:41:05Z",
  "locale": "en-US",
  "displayName": "My Endpoint",
  "description": "My Updated Endpoint Description"
}

使用上一个响应正文中的“日志”URI 发出 HTTP GET 请求。 将 YourEndpointId 替换为终结点 ID,将 YourSubscriptionKey 替换为语音资源密钥,将 YourServiceRegion 替换为语音资源区域。

curl -v -X GET "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.1/endpoints/YourEndpointId/files/logs" -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey"

每个日志文件的位置(其中包含更多详细信息)将在响应正文中返回。

日志记录数据在 Microsoft 拥有的存储上可以使用 30 天,之后会被删除。 如果你自己的存储帐户已关联到 Azure AI 服务订阅,则不会自动删除日志记录数据。

后续步骤