数字内容生产线 METASTUDIO-控制数字人直播过程:Go

时间:2023-11-28 10:24:42

Go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    metastudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/metastudio/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/metastudio/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/metastudio/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := metastudio.NewMetaStudioClient(
        metastudio.MetaStudioClientBuilder().
            WithRegion(region.ValueOf("cn-north-4")).
            WithCredential(auth).
            Build())

    request := &model.ExecuteSmartLiveCommandRequest{}
	var paramsControlSmartLiveReq interface{} = "{\"text_config\":{\"text\":\"看到评论区有观众问问题,我来响应下。\"}}"
	request.Body = &model.ControlSmartLiveReq{
		Params: &paramsControlSmartLiveReq,
		Command: model.GetControlSmartLiveReqCommandEnum().INSERT_PLAY_SCRIPT,
	}
	response, err := client.ExecuteSmartLiveCommand(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
support.huaweicloud.com/api-metastudio/ExecuteSmartLiveCommand.html