您的位置:首页 > 游戏 > 游戏 > 168工程信息网_装修设计合同标准范本_网络营销方案策划案例_软件开发公司排行榜

168工程信息网_装修设计合同标准范本_网络营销方案策划案例_软件开发公司排行榜

2025/5/6 2:49:49 来源:https://blog.csdn.net/qq_41575489/article/details/147549063  浏览:    关键词:168工程信息网_装修设计合同标准范本_网络营销方案策划案例_软件开发公司排行榜
168工程信息网_装修设计合同标准范本_网络营销方案策划案例_软件开发公司排行榜

腾讯云对象存储数据万象(Cloud Infinite,CI)为用户提供图片、视频、语音、文本等文件的内容安全智能审核服务,帮助用户有效识别涉黄、违法违规和广告审核,规避运营风险。本文以音频审核为例给出go语言示例代码与相应结果。

一、预备条件

  1. 获取API密钥,不可泄漏
    https://console.cloud.tencent.com/cam/capi
  2. 将SecretId与SecretKey写到环境变量

二、实现代码

package mainimport ("context""fmt""net/http""net/url""os""path/filepath""github.com/gin-gonic/gin"cos "github.com/tencentyun/cos-go-sdk-v5"
)var cosClient *cos.Clientfunc initCOSClient() error {secretID := os.Getenv("SecretId")secretKey := os.Getenv("SecretKey")if secretID == "" || secretKey == "" {return fmt.Errorf("SecretId and SecretKey environment variables are required")}bu, _ := url.Parse("https://radio-1259203851.cos.ap-shanghai.myqcloud.com")cu, _ := url.Parse("https://radio-1259203851.ci.ap-shanghai.myqcloud.com")b := &cos.BaseURL{BucketURL: bu, CIURL: cu}cosClient = cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{SecretID:  secretID,SecretKey: secretKey,},})return nil
}func main() {if err := initCOSClient(); err != nil {fmt.Printf("Failed to initialize COS client: %v\n", err)fmt.Println("Please set the following environment variables:")fmt.Println("export SecretId=YOUR_SECRET_ID")fmt.Println("export SecretKey=YOUR_SECRET_KEY")os.Exit(1)}r := gin.Default()// 文件上传接口r.POST("/upload", func(c *gin.Context) {file, err := c.FormFile("file")if err != nil {c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})return}// 保存上传的文件到临时目录tempDir := "temp"if err := os.MkdirAll(tempDir, 0755); err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}tempFilePath := filepath.Join(tempDir, file.Filename)if err := c.SaveUploadedFile(file, tempFilePath); err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}// 上传文件到COScosKey := "audios/" + file.Filename_, err = cosClient.Object.PutFromFile(context.Background(), cosKey, tempFilePath, nil)if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error":   err.Error(),"message": "Failed to upload file to COS",})return}// 提交审核任务opt := &cos.PutAudioAuditingJobOptions{InputObject: cosKey,Conf:        &cos.AudioAuditingJobConf{},}res, _, err := cosClient.CI.PutAudioAuditingJob(context.Background(), opt)if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error":   err.Error(),"message": "Failed to submit audio auditing job",})return}// 清理临时文件os.Remove(tempFilePath)// 返回任务IDc.JSON(http.StatusOK, gin.H{"job_id":  res.JobsDetail.JobId,"cos_key": cosKey,})})// 查询审核结果接口r.GET("/result/:job_id", func(c *gin.Context) {jobID := c.Param("job_id")// 查询审核结果res, _, err := cosClient.CI.GetAudioAuditingJob(context.Background(), jobID)if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error":   err.Error(),"message": "Failed to get audio auditing result",})return}c.JSON(http.StatusOK, res)})// 启动服务器r.Run(":8080")
}

三、调用方法

  1. 上传文件
    使用postman,调用以下接口:
http://localhost:8080/upload

在这里插入图片描述

  1. 查询任务
    在这里插入图片描述
    查询任务的结果说明可参考:查询音频审核任务结果,需要重点关注的是result,该字段表示本次判定的审核结果,可以根据该结果,进行后续的操作。有效值:0(审核正常),1 (判定为违规敏感文件),2(疑似敏感,建议人工复核)。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com