Manual review for audio

更新时间:
复制 MD 格式

This topic describes how to use the Python software development kit (SDK) to perform a manual review of audio content.

Description

You can use manual review if the results of machine-assisted moderation for a voice file do not meet your expectations. For more information about the parameters, see VoiceAsyncManualScan.

You must use the Content Moderation endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.

Prerequisites

  • Python dependencies are installed. For more information, see Installation.

    Note

    You must use the required Python version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.

  • The Extension.Uploader utility class is downloaded and imported into your project.

Submit a manual review task for audio

# coding=utf-8
import uuid

from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import VoiceAsyncManualScanRequest
import json

# Note: To improve detection performance, reuse the instantiated client and avoid creating repeated connections.
# Common ways to get environment variables:
# Get the AccessKey ID of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Get the AccessKey secret of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Get the AccessKey ID of a RAM user from an environment variable", "Get the AccessKey secret of a RAM user from an environment variable", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = VoiceAsyncManualScanRequest.VoiceAsyncManualScanRequest()
request.set_accept_format('JSON')

# The callback and seed parameters are used for callback notifications. They are optional.
request.set_content(
    json.dumps(
        {"tasks": [{"dataId": "Data ID", "url": "URL of the audio file to be scanned"}], "callback": "Webhook address",
         "seed": "Random string"}))

try:
    response = clt.do_action_with_exception(request)
    print response
except Exception, err:
    print err.__str__()

Query the result of a manual review task for audio

# coding=utf-8

from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import VoiceAsyncManualScanResultsRequest
import json

# Note: To improve detection performance, reuse the instantiated client and avoid creating repeated connections.
# Common ways to get environment variables:
# Get the AccessKey ID of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Get the AccessKey secret of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Get the AccessKey ID of a RAM user from an environment variable", "Get the AccessKey secret of a RAM user from an environment variable", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = VoiceAsyncManualScanResultsRequest.VoiceAsyncManualScanResultsRequest()
request.set_accept_format('JSON')

request.set_content(json.dumps(["ID of the manual audio review task"]))

try:
    response = clt.do_action_with_exception(request)
    print response
except Exception, err:
    print err.__str__()