Skip to content

Commit 4518f8f

Browse files
author
wanjiewu
committed
语音识别热词相关接口
1 parent b0d535d commit 4518f8f

File tree

3 files changed

+384
-0
lines changed

3 files changed

+384
-0
lines changed

ci_media.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4184,3 +4184,139 @@ func (s *CIService) CreateMultiGeneratePlayListJobs(ctx context.Context, opt *Cr
41844184
resp, err := s.client.send(ctx, &sendOpt)
41854185
return &res, resp, err
41864186
}
4187+
4188+
type VocabularyWeight struct {
4189+
Vocabulary string `xml:"Vocabulary,omitempty"`
4190+
Weight int `xml:"Weight,omitempty"`
4191+
}
4192+
4193+
// CreateAsrVocabularyTableOptions TODO
4194+
type CreateAsrVocabularyTableOptions struct {
4195+
XMLName xml.Name `xml:"Request"`
4196+
TableName string `xml:"TableName,omitempty"`
4197+
TableDescription string `xml:"TableDescription,omitempty"`
4198+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4199+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4200+
}
4201+
4202+
// CreateAsrVocabularyTableResult TODO
4203+
type CreateAsrVocabularyTableResult struct {
4204+
XMLName xml.Name `xml:"Response"`
4205+
Code string `xml:"Code,omitempty"`
4206+
Message string `xml:"Message,omitempty"`
4207+
TableId string `xml:"TableId,omitempty"`
4208+
RequestId string `xml:"RequestId,omitempty"`
4209+
}
4210+
4211+
func (s *CIService) CreateAsrVocabularyTable(ctx context.Context, opt *CreateAsrVocabularyTableOptions) (*CreateAsrVocabularyTableResult, *Response, error) {
4212+
var res CreateAsrVocabularyTableResult
4213+
sendOpt := sendOptions{
4214+
baseURL: s.client.BaseURL.CIURL,
4215+
uri: "/asrhotvocabtable",
4216+
method: http.MethodPost,
4217+
body: opt,
4218+
result: &res,
4219+
}
4220+
resp, err := s.client.send(ctx, &sendOpt)
4221+
return &res, resp, err
4222+
}
4223+
4224+
// DeleteAsrVocabularyTable TODO
4225+
func (s *CIService) DeleteAsrVocabularyTable(ctx context.Context, tableId string) (*Response, error) {
4226+
sendOpt := sendOptions{
4227+
baseURL: s.client.BaseURL.CIURL,
4228+
uri: "/asrhotvocabtable/" + tableId,
4229+
method: http.MethodDelete,
4230+
}
4231+
resp, err := s.client.send(ctx, &sendOpt)
4232+
return resp, err
4233+
}
4234+
4235+
// CreateAsrVocabularyTableOptions TODO
4236+
type UpdateAsrVocabularyTableOptions struct {
4237+
XMLName xml.Name `xml:"Request"`
4238+
TableId string `xml:"TableId,omitempty"`
4239+
TableName string `xml:"TableName,omitempty"`
4240+
TableDescription string `xml:"TableDescription,omitempty"`
4241+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4242+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4243+
}
4244+
4245+
type UpdateAsrVocabularyTableResult CreateAsrVocabularyTableResult
4246+
4247+
// UpdateAsrVocabularyTable TODO
4248+
func (s *CIService) UpdateAsrVocabularyTable(ctx context.Context, opt *UpdateAsrVocabularyTableOptions) (*UpdateAsrVocabularyTableResult, *Response, error) {
4249+
var res UpdateAsrVocabularyTableResult
4250+
sendOpt := sendOptions{
4251+
baseURL: s.client.BaseURL.CIURL,
4252+
uri: "/asrhotvocabtable",
4253+
method: http.MethodPut,
4254+
body: opt,
4255+
result: &res,
4256+
}
4257+
resp, err := s.client.send(ctx, &sendOpt)
4258+
return &res, resp, err
4259+
}
4260+
4261+
type VocabularyTable struct {
4262+
TableId string `xml:"TableId,omitempty"`
4263+
TableName string `xml:"TableName,omitempty"`
4264+
TableDescription string `xml:"TableDescription,omitempty"`
4265+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4266+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4267+
CreateTime string `xml:"CreateTime,omitempty"`
4268+
UpdateTime string `xml:"UpdateTime,omitempty"`
4269+
}
4270+
4271+
// DescribeAsrVocabularyTableResult TODO
4272+
type DescribeAsrVocabularyTableResult struct {
4273+
XMLName xml.Name `xml:"Response"`
4274+
RequestId string `xml:"RequestId,omitempty"`
4275+
TableId string `xml:"TableId,omitempty"`
4276+
TableName string `xml:"TableName,omitempty"`
4277+
TableDescription string `xml:"TableDescription,omitempty"`
4278+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4279+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4280+
CreateTime string `xml:"CreateTime,omitempty"`
4281+
UpdateTime string `xml:"UpdateTime,omitempty"`
4282+
}
4283+
4284+
// DescribeAsrVocabularyTable 查询指定的语音识别热词表
4285+
func (s *CIService) DescribeAsrVocabularyTable(ctx context.Context, tableId string) (*DescribeAsrVocabularyTableResult, *Response, error) {
4286+
var res DescribeAsrVocabularyTableResult
4287+
sendOpt := sendOptions{
4288+
baseURL: s.client.BaseURL.CIURL,
4289+
uri: "/asrhotvocabtable/" + tableId,
4290+
method: http.MethodGet,
4291+
result: &res,
4292+
}
4293+
resp, err := s.client.send(ctx, &sendOpt)
4294+
return &res, resp, err
4295+
}
4296+
4297+
// DescribeAsrVocabularyTablesOptions TODO
4298+
type DescribeAsrVocabularyTablesOptions struct {
4299+
Offset int `url:"offset,omitempty"`
4300+
Limit int `url:"limit,omitempty"`
4301+
}
4302+
4303+
type DescribeAsrVocabularyTablesResult struct {
4304+
XMLName xml.Name `xml:"Response"`
4305+
RequestId string `xml:"RequestId,omitempty"`
4306+
TotalCount string `xml:"TotalCount,omitempty"`
4307+
VocabularyTable []VocabularyTable `xml:"VocabularyTable,omitempty"`
4308+
}
4309+
4310+
// DescribeAsrVocabularyTables 查询语音识别热词表列表
4311+
func (s *CIService) DescribeAsrVocabularyTables(ctx context.Context, opt *DescribeAsrVocabularyTablesOptions) (*DescribeAsrVocabularyTablesResult, *Response, error) {
4312+
var res DescribeAsrVocabularyTablesResult
4313+
sendOpt := sendOptions{
4314+
baseURL: s.client.BaseURL.CIURL,
4315+
uri: "/asrhotvocabtable",
4316+
optQuery: opt,
4317+
method: http.MethodGet,
4318+
result: &res,
4319+
}
4320+
resp, err := s.client.send(ctx, &sendOpt)
4321+
return &res, resp, err
4322+
}

ci_media_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,3 +3728,103 @@ func TestCIService_CreateMultiGeneratePlayListJobs(t *testing.T) {
37283728
t.Fatalf("CI.CreateMultiGeneratePlayListJobs returned errors: %v", err)
37293729
}
37303730
}
3731+
3732+
func TestCIService_CreateAsrVocabularyTable(t *testing.T) {
3733+
setup()
3734+
defer teardown()
3735+
3736+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3737+
testMethod(t, r, http.MethodPost)
3738+
})
3739+
3740+
opt := &CreateAsrVocabularyTableOptions{
3741+
TableName: "test",
3742+
TableDescription: "test",
3743+
VocabularyWeights: []VocabularyWeight{
3744+
{
3745+
Vocabulary: "test",
3746+
Weight: 10,
3747+
},
3748+
},
3749+
VocabularyWeightStr: "",
3750+
}
3751+
_, _, err := client.CI.CreateAsrVocabularyTable(context.Background(), opt)
3752+
if err != nil {
3753+
t.Fatalf("CI.CreateAsrVocabularyTable returned error: %v", err)
3754+
}
3755+
}
3756+
3757+
func TestCIService_DeleteAsrVocabularyTable(t *testing.T) {
3758+
setup()
3759+
defer teardown()
3760+
3761+
tableId := "123"
3762+
mux.HandleFunc(fmt.Sprintf("/asrhotvocabtable/%s", tableId), func(w http.ResponseWriter, r *http.Request) {
3763+
testMethod(t, r, http.MethodDelete)
3764+
})
3765+
3766+
_, err := client.CI.DeleteAsrVocabularyTable(context.Background(), tableId)
3767+
if err != nil {
3768+
t.Fatalf("CI.DeleteAsrVocabularyTable returned error: %v", err)
3769+
}
3770+
}
3771+
3772+
func TestCIService_UpdateAsrVocabularyTable(t *testing.T) {
3773+
setup()
3774+
defer teardown()
3775+
3776+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3777+
testMethod(t, r, http.MethodPut)
3778+
})
3779+
3780+
opt := &UpdateAsrVocabularyTableOptions{
3781+
TableId: "123",
3782+
TableName: "test",
3783+
TableDescription: "test",
3784+
VocabularyWeights: []VocabularyWeight{
3785+
{
3786+
Vocabulary: "test",
3787+
Weight: 10,
3788+
},
3789+
},
3790+
VocabularyWeightStr: "",
3791+
}
3792+
_, _, err := client.CI.UpdateAsrVocabularyTable(context.Background(), opt)
3793+
if err != nil {
3794+
t.Fatalf("CI.UpdateAsrVocabularyTable returned error: %v", err)
3795+
}
3796+
}
3797+
3798+
func TestCIService_DescribeAsrVocabularyTable(t *testing.T) {
3799+
setup()
3800+
defer teardown()
3801+
3802+
tableId := "123"
3803+
mux.HandleFunc(fmt.Sprintf("/asrhotvocabtable/%s", tableId), func(w http.ResponseWriter, r *http.Request) {
3804+
testMethod(t, r, http.MethodGet)
3805+
})
3806+
3807+
_, _, err := client.CI.DescribeAsrVocabularyTable(context.Background(), tableId)
3808+
if err != nil {
3809+
t.Fatalf("CI.DescribeAsrVocabularyTable returned error: %v", err)
3810+
}
3811+
}
3812+
3813+
func TestCIService_DescribeAsrVocabularyTables(t *testing.T) {
3814+
setup()
3815+
defer teardown()
3816+
3817+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3818+
testMethod(t, r, http.MethodGet)
3819+
})
3820+
3821+
opt := &DescribeAsrVocabularyTablesOptions{
3822+
Offset: 0,
3823+
Limit: 100,
3824+
}
3825+
3826+
_, _, err := client.CI.DescribeAsrVocabularyTables(context.Background(), opt)
3827+
if err != nil {
3828+
t.Fatalf("CI.DescribeAsrVocabularyTables returned error: %v", err)
3829+
}
3830+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
10+
"github.com/tencentyun/cos-go-sdk-v5"
11+
"github.com/tencentyun/cos-go-sdk-v5/debug"
12+
)
13+
14+
func log_status(err error) {
15+
if err == nil {
16+
return
17+
}
18+
if cos.IsNotFoundError(err) {
19+
// WARN
20+
fmt.Println("WARN: Resource is not existed")
21+
} else if e, ok := cos.IsCOSError(err); ok {
22+
fmt.Printf("ERROR: Code: %v\n", e.Code)
23+
fmt.Printf("ERROR: Message: %v\n", e.Message)
24+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
25+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
26+
// ERROR
27+
} else {
28+
fmt.Printf("ERROR: %v\n", err)
29+
// ERROR
30+
}
31+
}
32+
33+
func getClient() *cos.Client {
34+
u, _ := url.Parse("https://test-1234567890.cos.ap-chongqing.myqcloud.com")
35+
cu, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
36+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
37+
c := cos.NewClient(b, &http.Client{
38+
Transport: &cos.AuthorizationTransport{
39+
SecretID: os.Getenv("COS_SECRETID"),
40+
SecretKey: os.Getenv("COS_SECRETKEY"),
41+
Transport: &debug.DebugRequestTransport{
42+
RequestHeader: true,
43+
// Notice when put a large file and set need the request body, might happend out of memory error.
44+
RequestBody: true,
45+
ResponseHeader: true,
46+
ResponseBody: true,
47+
},
48+
},
49+
})
50+
return c
51+
}
52+
53+
func CreateAsrVocabularyTable() {
54+
// 创建语音识别词表
55+
c := getClient()
56+
opt := &cos.CreateAsrVocabularyTableOptions{
57+
TableName: "test",
58+
TableDescription: "test",
59+
VocabularyWeights: []cos.VocabularyWeight{
60+
{
61+
Vocabulary: "test",
62+
Weight: 10,
63+
},
64+
},
65+
}
66+
_, _, err := c.CI.CreateAsrVocabularyTable(context.Background(), opt)
67+
if err != nil {
68+
panic(err)
69+
}
70+
// fmt.Printf("%+v\n", res)
71+
}
72+
73+
func DescribeAsrVocabularyTables() {
74+
// 查询语音识别词表
75+
c := getClient()
76+
opt := &cos.DescribeAsrVocabularyTablesOptions{
77+
Offset: 0,
78+
Limit: 10,
79+
}
80+
_, _, err := c.CI.DescribeAsrVocabularyTables(context.Background(), opt)
81+
if err != nil {
82+
panic(err)
83+
}
84+
// fmt.Printf("%+v\n", res)
85+
}
86+
87+
func DeleteAsrVocabularyTable() {
88+
// 查询语音识别词表
89+
c := getClient()
90+
91+
tableId := "c0398427aa1911eebe3c446a2eb5fd98"
92+
93+
_, err := c.CI.DeleteAsrVocabularyTable(context.Background(), tableId)
94+
if err != nil {
95+
panic(err)
96+
}
97+
// fmt.Printf("%+v\n", res)
98+
}
99+
100+
func DescribeAsrVocabularyTable() {
101+
// 查询语音识别词表
102+
c := getClient()
103+
104+
tableId := "fc6bd0ce320d11ef8484525400aec391"
105+
106+
res, _, err := c.CI.DescribeAsrVocabularyTable(context.Background(), tableId)
107+
if err != nil {
108+
panic(err)
109+
}
110+
fmt.Printf("%+v\n", res)
111+
}
112+
113+
func UpdateAsrVocabularyTable() {
114+
// 查询语音识别词表
115+
c := getClient()
116+
117+
tableId := "fc6bd0ce320d11ef8484525400aec391"
118+
opt := &cos.UpdateAsrVocabularyTableOptions{
119+
TableName: "test",
120+
TableDescription: "test",
121+
TableId: tableId,
122+
VocabularyWeights: []cos.VocabularyWeight{
123+
{
124+
Vocabulary: "test",
125+
Weight: 10,
126+
},
127+
},
128+
}
129+
_, _, err := c.CI.UpdateAsrVocabularyTable(context.Background(), opt)
130+
if err != nil {
131+
panic(err)
132+
}
133+
// fmt.Printf("%+v\n", res)
134+
135+
res, _, err := c.CI.DescribeAsrVocabularyTable(context.Background(), tableId)
136+
if err != nil {
137+
panic(err)
138+
}
139+
fmt.Printf("%+v\n", res)
140+
}
141+
142+
func main() {
143+
// CreateAsrVocabularyTable()
144+
// DescribeAsrVocabularyTables()
145+
// DeleteAsrVocabularyTable()
146+
// DescribeAsrVocabularyTable()
147+
UpdateAsrVocabularyTable()
148+
}

0 commit comments

Comments
 (0)