Manual audio review

更新时间:
复制 MD 格式

This topic describes how to use the PHP software development kit (SDK) to manually review audio.

Feature description

If the audio detection results do not meet your expectations, you can perform a manual review. For more information about the parameters, see the Audio Manual Review API documentation.

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 PHP dependencies have been installed. For more information, see Install PHP dependencies.

Note

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

Submit a manual audio review task

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: To improve detection performance, reuse the instantiated client and avoid repeatedly establishing connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a Resource Access Management (RAM) user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('AccessKey ID from environment variable', 'AccessKey secret from environment variable')
        ->timeout(10) // Timeout period: 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout period.
        ->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout period.
        ->regionId('cn-shanghai')
        ->asDefaultClient();
    
    $task1 = array('dataId' => 'Business data ID',
        'url' => 'URL of the audio file to be reviewed',
    );

    // The callback and seed parameters are optional and are used for callback notifications.
    $result = Green::v20180509()->voiceAsyncManualScan()
        ->timeout(10) // Timeout period: 10 seconds. This request timeout setting is valid only for the current request.
        ->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This request timeout setting is valid only for the current request.
        ->body(json_encode(array('tasks' => array($task1),
            'callback' => 'Webhook address', 'seed' => 'Random string')))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}

Query the results of a manual audio review task

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: To improve detection performance, reuse the instantiated client and avoid repeatedly establishing connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a Resource Access Management (RAM) user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('AccessKey ID from environment variable', 'AccessKey secret from environment variable')
        ->timeout(10) // Timeout period: 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout period.
        ->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout period.
        ->regionId('cn-shanghai')
        ->asDefaultClient();

    $result = Green::v20180509()->voiceAsyncManualScanResults()
        ->timeout(10) // Timeout period: 10 seconds. This request timeout setting is valid only for the current request.
        ->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This request timeout setting is valid only for the current request.
        ->body(json_encode(array('Manual audio review task ID')))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}