Manual audio review
This topic describes how to use the Go software development kit (SDK) to manually review audio content.
Description
If the audio moderation results do not meet your expectations, you can perform a manual review. For more information about the parameters, see the Manual audio 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.
-
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
Before you begin, make sure you have:
Installed Go dependencies. See Installation for the required Go version. Using an unsupported version causes subsequent operation calls to fail.
A RAM user AccessKey ID and AccessKey secret stored as environment variables:
ALIBABA_CLOUD_ACCESS_KEY_IDALIBABA_CLOUD_ACCESS_KEY_SECRET
Submit a manual audio review task
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: To improve moderation performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common methods to get environment variables:
* Get the AccessKey ID of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Get the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Get the AccessKey ID of the RAM user from an environment variable.",
"Get the AccessKey secret of the RAM user from an environment variable.")
if _err != nil {
fmt.Println(_err.Error())
return
}
task := map[string]interface{}{"dataId": "data ID", "url": "URL of the audio to be moderated"}
// The callback and seed parameters are optional. They are used for webhook notifications.
content, _ := json.Marshal(
map[string]interface{}{
"tasks": [...]map[string]interface{}{task},
"callback": "webhook address", "seed": "random string",
},
)
request := green.CreateVoiceAsyncManualScanRequest()
request.SetContent(content)
response, err := client.VoiceAsyncManualScan(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}Query the result of a manual audio review task
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: To improve moderation performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common methods to get environment variables:
* Get the AccessKey ID of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Get the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Get the AccessKey ID of the RAM user from an environment variable.",
"Get the AccessKey secret of the RAM user from an environment variable.")
if _err != nil {
fmt.Println(_err.Error())
return
}
content, _ := json.Marshal([...]string{"ID of the manual audio review task"})
request := green.CreateVoiceAsyncManualScanResultsRequest()
request.SetContent(content)
response, err := client.VoiceAsyncManualScanResults(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}