Manual audio review

更新时间:
复制 MD 格式

This topic describes how to perform a manual review of audio files using the .NET software development kit (SDK) for AI Guardrails.

Feature description

If an audio moderation result does not meet your expectations, you can perform a manual review. For more information about the parameters, see the Manual audio review API reference.

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

Note
  • This SDK supports only public audio URLs. It does not support local files or binary data.

  • Supported URL types:

    • Public HTTP/HTTPS URLs that do not exceed 2048 characters in length.

    • Alibaba Cloud OSS URL: oss://<bucket-name>.<endpoint>/<object-name>. You must authorize AI Guardrails to access the destination OSS bucket. The bucket and the AI Guardrails service must be in the same region. For more information, see Authorize AI Guardrails to access an OSS bucket.

Prerequisites

The .NET dependencies must be installed. For instructions, see Install .NET dependencies.

Note

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

Submit a manual audio review task

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * Common methods to obtain environment variables:
             *     Obtain the AccessKey ID of a Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of a RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "Obtain the AccessKey ID of the RAM user from an environment variable.",
                    "Obtain the AccessKey secret of the RAM user from an environment variable.");
            // Note: Reuse the instantiated client to improve moderation performance and avoid repeated connections.
            DefaultAcsClient client = new DefaultAcsClient(profile);

            VoiceAsyncManualScanRequest request = new VoiceAsyncManualScanRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> task1 = new Dictionary<string, object>();
            task1.Add("dataId", "The ID of the data to be moderated");
            task1.Add("url", "The URL of the audio file to be moderated");

            // The callback and seed parameters are used for callback notifications and are optional.
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("bizType", "The business scenario");
            httpBody.Add("callback", "The webhook address");
            httpBody.Add("seed", "A random string");
            httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                VoiceAsyncManualScanResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

Query the results of a manual audio review task

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * Common methods to obtain environment variables:
             *     Obtain the AccessKey ID of a Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of a RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "Obtain the AccessKey ID of the RAM user from an environment variable.",
                    "Obtain the AccessKey secret of the RAM user from an environment variable.");
            // Note: Reuse the instantiated client to improve moderation performance and avoid repeated connections.
            DefaultAcsClient client = new DefaultAcsClient(profile);

            VoiceAsyncManualScanResultsRequest request = new VoiceAsyncManualScanResultsRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            List<string> tasks = new List<string>();
            tasks.Add("The ID of the manual audio review task");

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(tasks)), "utf-8", FormatType.JSON);
            try
            {
                VoiceAsyncManualScanResultsResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}