Asynchronous audio moderation
This topic describes how to use an API operation to asynchronously moderate audio content. AI Guardrails helps you detect risks or violations in audio files or audio streams, such as live streams. Risks and violations include spam, advertisements, political content, terrorist content, abuse, pornography, excessive junk content, contraband, and meaningless content.
Usage notes for asynchronous audio moderation
The /green/voice/asyncscan API operation performs asynchronous audio moderation.
You can call this operation to create asynchronous audio moderation tasks. For more information about how to construct an HTTP request, see Request structure. You can also use a pre-built HTTP request. For more information, see SDK overview.
By default, audio moderation detects Mandarin Chinese. To detect other languages or dialects, contact your account manager. Other languages include English, Japanese, Spanish, Arabic, French, Indonesian, and Vietnamese. Dialects include Cantonese, Sichuanese, Hubei dialect, Shaanxi dialect, Shanxi dialect, Henan dialect, Northeastern dialect, Tianjin dialect, Gansu dialect, Guizhou dialect, Yunnan dialect, Jiangxi dialect, Guangxi dialect, Hunan dialect, Shandong dialect, Suzhou dialect, Zhejiang dialect, Shanghainese, and Minnan.
-
Billing information:
This is a paid API operation. For more information about billing, see Content Moderation Pricing.
-
Response:
Asynchronous detection tasks do not return results in real time. You must use a callback or polling to retrieve the results, which are stored for up to one hour.
-
Obtain results through callbacks: When you submit an asynchronous moderation task, specify the callback parameter in the request to automatically receive the moderation results. For more information, see Request parameters for asynchronous moderation.
-
Obtain results through polling: When you submit an asynchronous moderation task, you do not need to specify the callback parameter. After you submit the task, call the result query operation to obtain the moderation results. For more information, see Usage notes for querying asynchronous audio moderation results.
-
-
Audio file requirements:
-
The audio file size must be less than 200 MB.
-
Supported audio file formats: MP3, WAV, AAC, WMA, OGG, M4A, AMR, AUDIO, and M3U8.
-
Supported video file formats that contain audio: AVI, FLV, MP4, MPG, ASF, WMV, MOV, RMVB, and RM.
-
-
Audio stream requirements:
-
The audio stream duration must be less than 24 hours.
-
Supported audio stream protocols: HTTP, RTMP, and RTSP.
-
Supported audio stream formats: M3U8 and FLV.
-
QPS limit
The queries per second (QPS) limit for this API is 50 per user, with a concurrency limit of 20 streams. This means a maximum of 20 tasks can be processed at the same time. To increase the concurrency limit, contact your business manager. Exceeding these limits triggers throttling, which can impact your business. Plan your calls accordingly.
If real-time processing is not a high priority, we recommend that you enable offline detection mode. In this mode, the detection task starts within 24 hours after submission.
Request parameters for asynchronous moderation
|
Name |
Type |
Required |
Example |
Description |
|
bizType |
String |
No |
default |
This field identifies your business scenario. You can create a business scenario in the Content Moderation console. For more information, see Customize moderation rules. |
|
scenes |
StringArray |
Yes |
antispam |
The moderation scenario. The value is fixed to antispam. |
|
live |
Boolean |
No |
false |
Specifies whether to moderate an audio stream, such as a live stream. Valid values:
Note
To moderate an audio stream, you must set this parameter to true. |
|
offline |
Boolean |
No |
false |
Specifies whether to enable offline moderation mode. Valid values:
Note
This parameter applies only to audio file moderation, not to audio stream moderation. |
|
callback |
String |
No |
http://aliyundoc.com |
The URL to which you want to receive callback notifications for the detection results. The URL must use the HTTP or HTTPS protocol. If you leave this parameter empty, you must periodically poll for the detection results. The
Note
After your callback server receives a result notification, it must return an HTTP status code of 200 to indicate success. Any other status code is treated as a failure. If the notification fails, Content Moderation retries up to 16 times until it succeeds. If it still fails after 16 retries, no more attempts are made. We recommend that you check the status of your callback endpoint. |
|
seed |
String |
No |
abc**** |
A random string used for the signature in the callback notification request. The string can contain letters, digits, and underscores (_), and must be 64 characters or less. Customize this string to verify the origin of callback requests. Note
This parameter is required when you use a callback. |
|
cryptType |
String |
No |
SHA256 |
The digest algorithm applied to the content of callback notifications. When you use callback notifications, Content Moderation concatenates
|
|
tasks |
JSONArray |
Yes |
The detection objects. Each element in the JSON array is a struct for a detection task. The array can contain a maximum of 100 elements. This means you can submit up to 100 pieces of content for moderation at a time. To submit 100 elements, you must increase the concurrent task limit to more than 100. For more information about the structure of each element, see task. |
|
Name |
Type |
Required |
Example |
Description |
|
clientInfo |
JSONObject |
No |
{"userId":"12023****","userNick":"Mike","userType":"others"} |
The client information. For more information, see the common query parameters in Common parameters. The server merges the global clientInfo with the individual clientInfo specified for the request. Note
The individual clientInfo has a higher priority. |
|
dataId |
String |
No |
1a90c9d6-6a81-42db-bbe1-e36102f3**** |
The data ID of the detection object. This ID can contain uppercase and lowercase letters, digits, underscores (_), hyphens (-), and periods (.), and must be 128 characters or less. Use it to uniquely identify your business data. |
|
liveId |
String |
No |
liveId1**** |
The ID of the audio live stream. This parameter is used to remove duplicate audio live stream tasks and prevent repeated moderation. If you specify this parameter, AI Guardrails checks whether a moderation task is in progress for the live stream based on |
|
url |
String |
No |
http://aliyundoc.com/test.flv |
The URL of the object to detect.
|
Response parameters for asynchronous moderation
|
Name |
Type |
Example |
Description |
|
code |
Integer |
200 |
The error code. It is the same as the HTTP status code. For more information, see Common error codes. |
|
msg |
String |
OK |
The message that is returned for the request. |
|
dataId |
String |
1a90c9d6-6a81-42db-bbe1-e36102f3**** |
The data ID of the detection object. Note
If dataId was passed in the detection request, the same dataId is returned here. |
|
taskId |
String |
voice3VayNFGf43J6S9mHYp1HYJ-12**** |
The ID of the moderation task. |
Examples for asynchronous moderation
Sample request
http(s)://[Endpoint]/green/voice/asyncscan
&<Common request parameters>
{
"scenes": [
"antispam"
],
"live": true,
"tasks": [
{
"dataId": "1a90c9d6-6a81-42db-bbe1-e36102f3****",
"url": "http://aliyundoc.com/test.flv"
}
]
}
Sample success response
{
"msg": "OK",
"code": 200,
"requestId": "33921869-CF8A-4E62-8C31-44F37341****",
"data": [
{
"code": 200,
"msg": "OK",
"dataId": "1a90c9d6-6a81-42db-bbe1-e36102f3****",
"taskId": "voice3VayNFGf43J6S9mHYp1HYJ-12****"
}
]
}
Usage notes for querying asynchronous audio moderation results
The /green/voice/results API operation queries the results of asynchronous audio moderation tasks.
You can call this operation to query the results of asynchronous audio moderation tasks. If you do not set a callback address when you submit an asynchronous audio moderation task, you must call this operation to poll for the moderation results. For more information about how to construct an HTTP request, see Request structure. You can also use a pre-built HTTP request. For more information, see SDK overview.
-
Billing information:
This API operation is free of charge.
-
Query timeout:
-
For audio file moderation tasks, each query or callback returns only the results of completed tasks. We recommend that you set the query interval to 30 seconds. The moderation results are stored for 4 hours. You must query and save the results promptly.
-
For audio stream moderation tasks, each poll returns the moderation results of the last 10 detected audio segments. We recommend that you set the query interval to 30 seconds. If you obtain the audio stream moderation results through callbacks, the system sends a callback notification each time it detects audio content.
-
QPS limit
The queries per second (QPS) limit for this API is 50 per user. Exceeding this limit triggers throttling, which can impact your business. Plan your calls accordingly.
Request parameters for querying results
|
Name |
Type |
Required |
Example value |
Description |
|
body |
JSONArray |
Yes |
voice3VayNFGf43J6S9mHYp1HYJ-12**** |
A list of taskId values for the detection tasks you want to query. The array can contain up to 100 elements. You can obtain the taskId from the response after you submit a detection task. |
Response parameters for querying results
|
Name |
Type |
Example |
Description |
|
code |
Integer |
200 |
The error code. This is consistent with the HTTP status code.
For more information, see Common error codes. Note
Only the code 280 indicates that the task is in progress and you need to continue to poll for the moderation results. Other codes indicate that the audio moderation task is complete. If the audio moderation task is not complete but is abnormally terminated due to a network exception or other reasons, you can resubmit the asynchronous audio moderation task. |
|
msg |
String |
OK |
The message that is returned for the request. |
|
dataId |
String |
1a90c9d6-6a81-42db-bbe1-e36102f3**** |
The data ID of the detection object. Note
If dataId was passed in the detection request, the same dataId is returned here. |
|
taskId |
String |
voice3VayNFGf43J6S9mHYp1HYJ-12**** |
The ID of the moderation task. |
|
url |
String |
https://aliyundoc.com |
The URL of the object to detect.
|
|
new_url |
String |
https://example.com |
If the moderated content is an audio stream, this parameter indicates the address of the stored file after the moderation is complete. The signature is valid for 30 minutes. Store the file promptly. Note
|
|
results |
JSONArray |
The moderation results that are returned when the moderation is successful (code=200). The results contain one or more elements. Each element is a struct that corresponds to a scenario. For more information about the structure of each element, see result. |
|
Name |
Type |
Sample value |
Description |
|
scene |
String |
antispam |
The moderation scenario. This corresponds to the scenario in the request. The value is fixed to antispam. |
|
label |
String |
customized |
The category of the moderation result. Valid values:
|
|
suggestion |
String |
block |
The recommended subsequent operation. Valid values:
|
|
rate |
Float |
99.91 |
The confidence score. Valid values: 0 (lowest confidence) to 100 (highest confidence). If the suggestion is pass, the higher the confidence score, the more likely the content is compliant. If the suggestion is review or block, the higher the confidence score, the more likely the content is non-compliant. Important
We recommend that you use the suggestion and label (or sublabel, for some API operations) fields to determine whether the content is in violation. |
|
details |
JSONArray |
The details of the text that corresponds to the audio. Each element corresponds to a sentence and contains one or more elements. For more information about the structure of each element, see detail. Note
If you enable audio evidence storage and the detection object is an audio stream, the OSS URL of the stored audio shard is returned. For more information, see Moderation results. |
|
Name |
Type |
Example value |
Description |
|
startTime |
Integer |
0 |
The start time of the sentence. Unit: seconds. |
|
endTime |
Integer |
4065 |
The end time of the sentence. Unit: seconds. |
|
text |
String |
Disgusting |
The result of converting the audio to text. |
|
label |
String |
customized |
The category of the moderation result. Valid values:
|
|
persons |
JSONArray |
[{"name":"Sensitive Person A"}] |
The voiceprint recognition result. This parameter is returned if the voiceprint of a sensitive person is hit. The struct is as follows:
Note
By default, this parameter is not returned. If you need this parameter, contact your account manager. |
|
hintWords |
JSONArray |
"[{"context":"sensitive word"}]" |
The information about the risk keywords that are hit in the text of the audio. This information indicates the reason for the violation. Multiple hit keywords may be returned. For more information about the structure, see hintWords. |
|
keyword |
String |
Disgusting |
The hit custom keyword if a custom keyword is hit. |
|
libName |
String |
test |
The library that contains the hit custom keyword if a custom keyword is hit. |
|
url |
String |
https://aliyundoc.com |
If the moderated content is an audio stream, this parameter indicates the temporary access address of the audio stream that corresponds to the text segment. The address is valid for 30 minutes. Store the address promptly. Note
By default, this parameter is not returned. If you need this parameter, contact your account manager. |
|
Name |
Type |
Example value |
Description |
|
context |
String |
Disgusting |
The content of the risk keyword that is hit in the text of the audio. |
Examples for querying results
Sample request
http(s)://[Endpoint]/green/voice/results
&<Common request parameters>
[
"voice3VayNFGf43J6S9mHYp1HYJ-12****"
]
Sample success response
{
"msg": "OK",
"code": 200,
"data": [
{
"code": 200,
"dataId": "1a90c9d6-6a81-42db-bbe1-e36102f3****",
"results": [
{
"rate": 99.91,
"suggestion": "block",
"details": [
{
"libName": "test",
"startTime": 0,
"endTime": 4065,
"label": "customized",
"text": "Disgusting",
"keyword": "Disgusting"
},
{
"startTime": 4430,
"endTime": 10065,
"label": "review",
"persons": [
{
"name": "Sensitive Person A"
}
],
"text": "Test"
},
{
"libName": "Audio Test",
"startTime": 11670,
"endTime": 14685,
"label": "customized",
"text": "Ultra-low discount, big sale",
"keyword": "Sale"
},
{
"startTime": 14685,
"endTime": 16065,
"label": "ad",
"text": "Hello"
}
],
"label": "customized"
}
],
"taskId": "voice3VayNFGf43J6S9mHYp1HYJ-12****"
}
],
"requestId": "5A7A6198-6960-4DDC-B67E-58A6F1A4****"
}