在使用语音转文本或语音翻译时,可以启用音频输入和已识别语音的日志记录功能。 对于语音翻译,仅记录原始音频的音频和听录。 不记录翻译。 本文介绍了如何启用、访问和删除音频和听录日志。
音频和听录日志可用作自定义语音识别模型训练的输入。 你可能有其他用例。
警告
当需要输入音频的确切记录时,不要依赖于音频和听录日志。 在负载高峰期,该服务会优先处理听录任务的硬件资源。 这可能会导致未记录音频的次要部分。 这种情况很少见,但也有可能。
基本模型终结点和自定义模型终结点的日志记录都异步完成。 语音服务将音频和听录日志存储在其内部存储中,而不是在本地写入。 日志保留 30 天。 在此时间段后,会自动删除日志。 但是,可以随时 删除 特定日志或一系列可用日志。
还可以使用自带存储 (BYOS) 技术将音频和听录日志存储在你拥有和控制的 Azure 存储帐户中,而不是语音服务本地。 请参阅本文中有关如何使用已启用 BYOS 的语音资源的详细信息。
默认禁用日志记录。 可以为 每个识别会话 或 每个自定义模型终结点 启用日志记录。
无论是使用默认的基本模型终结点还是 自定义模型 终结点,都可以启用单个识别会话的日志记录。
警告
对于自定义模型终结点,已部署终结点的日志记录设置优先于会话级别设置(SDK 或 REST API)。 如果已为自定义模型终结点启用日志记录,则忽略会话级别设置(无论设置为 true 还是 false)。 如果未为自定义模型终结点启用日志记录,则会话级别设置会确定日志记录是否处于活动状态。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechConfig 类实例的 EnableAudioLogging()
方法。
speechConfig.EnableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
string isAudioLoggingEnabled = speechConfig.GetProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechConfig
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechConfig 类实例的 EnableAudioLogging
方法。
speechConfig->EnableAudioLogging();
要检查是否已启用日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
string isAudioLoggingEnabled = speechConfig->GetProperty(PropertyId::SpeechServiceConnection_EnableAudioLogging);
使用此 speechConfig
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechConfig 类实例的 enableAudioLogging()
方法。
speechConfig.enableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
String isAudioLoggingEnabled = speechConfig.getProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechConfig
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechConfig 类实例的 enableAudioLogging()
方法。
speechConfig.enableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
var SpeechSDK;
SpeechSDK = speechSdk;
// <...>
string isAudioLoggingEnabled = speechConfig.getProperty(SpeechSDK.PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechConfig
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechConfig 类实例的 enable_audio_logging
方法。
speech_config.enable_audio_logging()
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
import azure.cognitiveservices.speech as speechsdk
# <...>
is_audio_logging_enabled = speech_config.get_property(property_id=speechsdk.PropertyId.SpeechServiceConnection_EnableAudioLogging)
使用此 speech_config
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SPXSpeechConfiguration 类实例的 enableAudioLogging
方法。
[speechConfig enableAudioLogging];
要检查是否启用了日志记录,请获取 SPXSpeechServiceConnectionEnableAudioLogging
属性的值:
NSString *isAudioLoggingEnabled = [speechConfig getPropertyById:SPXSpeechServiceConnectionEnableAudioLogging];
使用此 speechConfig
的每个 SpeechRecognizer 都已启用音频和听录日志记录。
对于语音翻译,仅记录原始音频的音频和听录。 不记录翻译。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechTranslationConfig 类实例的 EnableAudioLogging()
方法。
speechTranslationConfig.EnableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
string isAudioLoggingEnabled = speechTranslationConfig.GetProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechTranslationConfig
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechTranslationConfig 类实例的 EnableAudioLogging
方法。
speechTranslationConfig->EnableAudioLogging();
要检查是否已启用日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
string isAudioLoggingEnabled = speechTranslationConfig->GetProperty(PropertyId::SpeechServiceConnection_EnableAudioLogging);
使用此 speechTranslationConfig
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechTranslationConfig 类实例的 enableAudioLogging()
方法。
speechTranslationConfig.enableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
String isAudioLoggingEnabled = speechTranslationConfig.getProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechTranslationConfig
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechTranslationConfig 类实例的 enableAudioLogging()
方法。
speechTranslationConfig.enableAudioLogging();
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
var SpeechSDK;
SpeechSDK = speechSdk;
// <...>
string isAudioLoggingEnabled = speechTranslationConfig.getProperty(SpeechSDK.PropertyId.SpeechServiceConnection_EnableAudioLogging);
使用此 speechTranslationConfig
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SpeechTranslationConfig 类实例的 enable_audio_logging
方法。
speech_translation_config.enable_audio_logging()
要检查是否启用了日志记录,请获取 SpeechServiceConnection_EnableAudioLogging
属性的值:
import azure.cognitiveservices.speech as speechsdk
# <...>
is_audio_logging_enabled = speech_translation_config.get_property(property_id=speechsdk.PropertyId.SpeechServiceConnection_EnableAudioLogging)
使用此 speech_translation_config
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
要使用语音 SDK 启用音频和听录日志记录,请执行 SPXSpeechTranslationConfiguration 类实例的 enableAudioLogging
方法。
[speechTranslationConfig enableAudioLogging];
要检查是否启用了日志记录,请获取 SPXSpeechServiceConnectionEnableAudioLogging
属性的值:
NSString *isAudioLoggingEnabled = [speechTranslationConfig getPropertyById:SPXSpeechServiceConnectionEnableAudioLogging];
使用此 speechTranslationConfig
的每个 TranslationRecognizer 都已启用音频和听录日志记录。
如果将语音转文本 REST API 用于短音频,并且想要启用音频和听录日志记录,需要将查询参数和值 storeAudio=true
用作 REST 请求的一部分。 示例请求如下所示:
https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?language=en-US&storeAudio=true
此方法仅适用于自定义语音识别终结点。
可以在永久性自定义模型终结点设置中启用或禁用日志记录。 为自定义模型终结启用(打开)日志记录后,无需 使用 SDK 或 REST API 在识别会话级别 启用日志记录。 即使未为自定义模型终结点启用日志记录,也可以使用 SDK 或 REST API 在识别会话级别暂时启用日志记录。
警告
对于自定义模型终结点,已部署终结点的日志记录设置优先于会话级别设置(SDK 或 REST API)。 如果已为自定义模型终结点启用日志记录,则忽略会话级别设置(无论设置为 true 还是 false)。 如果未为自定义模型终结点启用日志记录,则会话级别设置会确定日志记录是否处于活动状态。
可以启用自定义模型终结点的音频和听录日志记录:
- 使用 Speech Studio、REST API 或语音 CLI 创建终结点时。 若要详细了解如何为自定义语音终结点启用日志记录,请参阅部署自定义语音模型。
- 在使用语音转文本 REST API 更新终结点(Endpoints_Update)时。 有关如何更新终结点的日志记录设置的示例,请参阅 关闭自定义模型终结点的日志记录。 但是,与其将
contentLoggingEnabled
属性设置为false
,不如将其设置为true
以启用终结点的日志记录。
要禁用自定义模型终结点的音频和听录日志记录,必须使用语音转文本 REST API 更新永久性终结点日志记录设置。 无法使用 Speech Studio 禁用现有自定义模型终结点的日志记录。
要关闭自定义终结点的日志记录,请使用语音转文本 REST API 的 Endpoints_Update 操作。 根据以下说明构造请求正文:
- 设置
properties
内的contentLoggingEnabled
属性。 将此属性设置为true
以启用终结点流量的日志记录。 将此属性设置为false
以禁用终结点流量的日志记录。
使用 URI 发出 HTTP PATCH 请求,如以下示例所示。 将 YourSubscriptionKey
替换为语音资源密钥,将 YourServiceRegion
替换为语音资源区域,将 YourEndpointId
替换为终结点 ID,并按前面所述设置请求正文属性。
curl -v -X PATCH -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey" -H "Content-Type: application/json" -d '{
"properties": {
"contentLoggingEnabled": false
},
}' "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/YourEndpointId"
你应该会收到以下格式的响应正文:
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"model": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/9e240dc1-3d2d-4ac9-98ec-1be05ba0e9dd"
},
"links": {
"logs": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/a07164e8-22d1-4eb7-aa31-bf6bb1097f37/files/logs",
"restInteractive": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"restConversation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"restDictation": "https://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"webSocketInteractive": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/interactive/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"webSocketConversation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/conversation/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37",
"webSocketDictation": "wss://chinanorth2.stt.speech.azure.cn/speech/recognition/dictation/cognitiveservices/v1?cid=a07164e8-22d1-4eb7-aa31-bf6bb1097f37"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"properties": {
"loggingEnabled": false
},
"lastActionDateTime": "2024-07-15T16:30:12Z",
"status": "Succeeded",
"createdDateTime": "2024-07-15T16:29:36Z",
"locale": "en-US",
"displayName": "My Endpoint",
"description": "My Endpoint Description"
}
响应正文应反映新设置。 响应(loggingEnabled
)中日志记录属性的名称不同于在请求(contentLoggingEnabled
)中设置的日志记录属性的名称。
可以使用语音转文本 REST API 访问音频和听录日志。 对于 自定义模型 终结点,还可以使用 Speech Studio。 请参阅以下部分的详细信息。
备注
日志记录数据保留 30 天。 在此时间段后,会自动删除日志。 但是,可以随时 删除 特定日志或一系列可用日志。
此方法仅适用于 自定义模型 终结点。
若要下载终结点日志,请执行以下操作:
- 登录 Speech Studio。
- 选择“自定义语音识别”> 你的项目名称 >“部署模型”。
- 按终结点名称选择链接。
- 在“内容日志记录”下,选择“下载日志”。
使用此方法,可以一次性下载所有可用的日志集。 无法在 Speech Studio 中下载所选日志集。
可以下载所有或部分可用日志集。
此方法适用于基本模型终结点和 自定义模型 终结点。 要列出并下载音频和听录日志:
- 基本模型:使用语音转文本 REST API 的 Endpoints_ListBaseModelLogs 操作。 此操作获取使用给定语言的默认基本模型时存储的音频和听录日志列表。
- 自定义模型终结点:使用语音转文本 REST API 的 Endpoints_ListLogs 操作。 此操作获取为给定终结点存储的音频和听录日志列表。
在一些情况下,可能需要获取可用日志的 ID。 例如,可能要删除特定日志,如后文所述。
要获取可用日志的 ID:
- 基本模型:使用语音转文本 REST API 的 Endpoints_ListBaseModelLogs 操作。 此操作获取使用给定语言的默认基本模型时存储的音频和听录日志列表。
- 自定义模型终结点:使用语音转文本 REST API 的 Endpoints_ListLogs 操作。 此操作获取为给定终结点存储的音频和听录日志列表。
以下是 Endpoints_ListLogs 的示例输出。 为简单起见,仅显示一个日志集:
{
"values": [
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/files/logs/2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_v2_json",
"name": "163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9.v2.json",
"kind": "Transcription",
"properties": {
"size": 79920
},
"createdDateTime": "2024-07-15T16:29:36Z",
"links": {
"contentUrl": "<Link to download log file>"
}
},
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/files/logs/2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_wav",
"name": "163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9.wav",
"kind": "Audio",
"properties": {
"size": 932966
},
"createdDateTime": "2024-07-15T16:29:36Z",
"links": {
"contentUrl": "<Link to download log file>"
}
}
]
}
每个音频和听录日志文件的位置都在响应正文中返回。 请参阅相应的 kind
属性,从而确定文件是包括音频("kind": "Audio"
)还是听录("kind": "Transcription"
)。
每个日志文件的日志 ID 都是 "self"
元素值中 URL 的最后一部分。 以下示例中的日志 ID 为 2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_v2_json
。
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/endpoints/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/files/logs/2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_v2_json"
日志记录数据保留 30 天。 在此时间段后,会自动删除日志。 但是,可以随时删除特定日志或一系列可用日志。
对于任何基本模型终结点或 自定义模型 终结点,都可以删除所有可用日志、给定期限内的日志或基于其日志 ID 的特定日志。 删除过程异步完成,可能需要几分钟、几小时、一天或更长时间,具体取决于日志文件的数量。
要删除音频和听录日志,必须使用语音转文本 REST API。 无法使用 Speech Studio 删除日志。
要删除所有日志或给定期限内的日志:
- 基本模型:使用语音转文本 REST API 的 Endpoints_DeleteBaseModelLogs 操作。
- 自定义模型终结点:使用语音转文本 REST API 的 Endpoints_DeleteLogs 操作。
(可选)设置音频日志删除的 endDate
(特定日期、UTC)。 预期格式:"yyyy-mm-dd"。 例如,"2023-03-15" 会删除 2023 年 3 月 15 日及之前的所有日志。
要按 ID 删除特定日志:
- 基本模型:使用语音转文本 REST API 的 Endpoints_DeleteBaseModelLog 操作。
- 自定义模型终结点:使用语音转文本 REST API 的 Endpoints_DeleteLog 操作。
有关如何获取日志 ID 的详细信息,请参阅上一部分使用语音转文本 REST API 获取日志 ID。
由于音频和听录日志具有单独的 ID(例如 本文前面示例 中的 ID 2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_v2_json
和 2023-03-13_163715__0420c53d-e6ac-4857-bce0-f39c3f9f5ff9_wav
),因此,如果要删除音频和听录日志,请 按 ID 请求执行单独删除。