Skip to content

Commit 3cb24d0

Browse files
committed
Merge branch 'asrjob' into 'master' (merge request !16)
新增语音识别任务
2 parents 1a1a581 + b720e89 commit 3cb24d0

File tree

2 files changed

+154
-2
lines changed

2 files changed

+154
-2
lines changed

ci_media.go

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ type MediaProcessJobOperation struct {
220220
Tag string `xml:"Tag,omitempty"`
221221
Output *JobOutput `xml:"Output,omitempty"`
222222
Transcode *Transcode `xml:"Transcode,omitempty"`
223-
Watermark *Watermark `xml:"Watermark,omitempty"`
223+
Watermark []Watermark `xml:"Watermark,omitempty"`
224224
TemplateId string `xml:"TemplateId,omitempty"`
225225
WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"`
226226
ConcatTemplate *ConcatTemplate `xml:"ConcatTemplate,omitempty"`
@@ -977,3 +977,87 @@ func (s *CIService) DescribeWorkflowExecution(ctx context.Context, runId string)
977977
resp, err := s.client.send(ctx, &sendOpt)
978978
return &res, resp, err
979979
}
980+
981+
type SpeechRecognition struct {
982+
ChannelNum string `xml:"ChannelNum,omitempty"`
983+
ConvertNumMode string `xml:"ConvertNumMode,omitempty"`
984+
EngineModelType string `xml:"EngineModelType,omitempty"`
985+
FilterDirty string `xml:"FilterDirty,omitempty"`
986+
FilterModal string `xml:"FilterModal,omitempty"`
987+
ResTextFormat string `xml:"ResTextFormat,omitempty"`
988+
}
989+
990+
type SpeechRecognitionResult struct {
991+
AudioTime float64 `xml:"AudioTime,omitempty"`
992+
Result []string `xml:"Result,omitempty"`
993+
}
994+
type ASRJobOperation struct {
995+
Tag string `xml:"Tag,omitempty"`
996+
Output *JobOutput `xml:"Output,omitempty"`
997+
SpeechRecognition *SpeechRecognition `xml:"SpeechRecognition,omitempty"`
998+
SpeechRecognitionResult *SpeechRecognitionResult `xml:"SpeechRecognitionResult,omitempty"`
999+
}
1000+
1001+
type CreateASRJobsOptions struct {
1002+
XMLName xml.Name `xml:"Request"`
1003+
Tag string `xml:"Tag,omitempty"`
1004+
Input *JobInput `xml:"Input,omitempty"`
1005+
Operation *ASRJobOperation `xml:"Operation,omitempty"`
1006+
QueueId string `xml:"QueueId,omitempty"`
1007+
CallBack string `xml:"CallBack,omitempty"`
1008+
}
1009+
1010+
type ASRJobDetail struct {
1011+
Code string `xml:"Code,omitempty"`
1012+
Message string `xml:"Message,omitempty"`
1013+
JobId string `xml:"JobId,omitempty"`
1014+
Tag string `xml:"Tag,omitempty"`
1015+
State string `xml:"State,omitempty"`
1016+
CreationTime string `xml:"CreationTime,omitempty"`
1017+
QueueId string `xml:"QueueId,omitempty"`
1018+
Input *JobInput `xml:"Input,omitempty"`
1019+
Operation *ASRJobOperation `xml:"Operation,omitempty"`
1020+
}
1021+
1022+
type CreateASRJobsResult struct {
1023+
XMLName xml.Name `xml:"Response"`
1024+
JobsDetail *ASRJobDetail `xml:"JobsDetail,omitempty"`
1025+
}
1026+
1027+
func (s *CIService) CreateASRJobs(ctx context.Context, opt *CreateASRJobsOptions) (*CreateASRJobsResult, *Response, error) {
1028+
var res CreateASRJobsResult
1029+
sendOpt := sendOptions{
1030+
baseURL: s.client.BaseURL.CIURL,
1031+
uri: "/asr_jobs",
1032+
method: http.MethodPost,
1033+
body: opt,
1034+
result: &res,
1035+
}
1036+
resp, err := s.client.send(ctx, &sendOpt)
1037+
return &res, resp, err
1038+
}
1039+
1040+
type DescribeMutilASRJobResult struct {
1041+
XMLName xml.Name `xml:"Response"`
1042+
JobsDetail []ASRJobDetail `xml:"JobsDetail,omitempty"`
1043+
NonExistJobIds []string `xml:"NonExistJobIds,omitempty"`
1044+
}
1045+
1046+
func (s *CIService) DescribeMultiASRJob(ctx context.Context, jobids []string) (*DescribeMutilASRJobResult, *Response, error) {
1047+
jobidsStr := ""
1048+
if len(jobids) < 1 {
1049+
return nil, nil, errors.New("empty param jobids")
1050+
} else {
1051+
jobidsStr = strings.Join(jobids, ",")
1052+
}
1053+
1054+
var res DescribeMutilASRJobResult
1055+
sendOpt := sendOptions{
1056+
baseURL: s.client.BaseURL.CIURL,
1057+
uri: "/asr_jobs/" + jobidsStr,
1058+
method: http.MethodGet,
1059+
result: &res,
1060+
}
1061+
resp, err := s.client.send(ctx, &sendOpt)
1062+
return &res, resp, err
1063+
}

example/CI/media_process/media_process.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,72 @@ func DescribeMultiWorkflowExecution() {
947947
fmt.Printf("%+v\n", describeWorkflowExecutionsRes)
948948
}
949949

950+
func InvokeASRJob() {
951+
u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com")
952+
cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com")
953+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
954+
c := cos.NewClient(b, &http.Client{
955+
Transport: &cos.AuthorizationTransport{
956+
SecretID: os.Getenv("COS_SECRETID"),
957+
SecretKey: os.Getenv("COS_SECRETKEY"),
958+
Transport: &debug.DebugRequestTransport{
959+
RequestHeader: true,
960+
// Notice when put a large file and set need the request body, might happend out of memory error.
961+
RequestBody: true,
962+
ResponseHeader: true,
963+
ResponseBody: true,
964+
},
965+
},
966+
})
967+
// CreateMediaJobs
968+
createJobOpt := &cos.CreateASRJobsOptions{
969+
Tag: "SpeechRecognition",
970+
Input: &cos.JobInput{
971+
Object: "abc.mp3",
972+
},
973+
Operation: &cos.ASRJobOperation{
974+
Output: &cos.JobOutput{
975+
Region: "ap-chongqing",
976+
Object: "music.txt",
977+
Bucket: "wwj-cq-1253960454",
978+
},
979+
SpeechRecognition: &cos.SpeechRecognition{
980+
ChannelNum: "1",
981+
EngineModelType: "8k_zh",
982+
},
983+
},
984+
QueueId: "p1db6a1a76ff04806b6af0d96e9bc80ab",
985+
}
986+
createJobRes, _, err := c.CI.CreateASRJobs(context.Background(), createJobOpt)
987+
log_status(err)
988+
fmt.Printf("%+v\n", createJobRes.JobsDetail)
989+
DescribeJobRes, _, err := c.CI.DescribeMultiASRJob(context.Background(), []string{createJobRes.JobsDetail.JobId})
990+
log_status(err)
991+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
992+
}
993+
994+
func DescribeASRJob() {
995+
u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com")
996+
cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com")
997+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
998+
c := cos.NewClient(b, &http.Client{
999+
Transport: &cos.AuthorizationTransport{
1000+
SecretID: os.Getenv("COS_SECRETID"),
1001+
SecretKey: os.Getenv("COS_SECRETKEY"),
1002+
Transport: &debug.DebugRequestTransport{
1003+
RequestHeader: true,
1004+
// Notice when put a large file and set need the request body, might happend out of memory error.
1005+
RequestBody: true,
1006+
ResponseHeader: true,
1007+
ResponseBody: true,
1008+
},
1009+
},
1010+
})
1011+
DescribeJobRes, _, err := c.CI.DescribeMultiASRJob(context.Background(), []string{"sa59de0a06a4711ec9b81df13272c69a9"})
1012+
log_status(err)
1013+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail[0].Operation.SpeechRecognitionResult)
1014+
}
1015+
9501016
func main() {
9511017
// InvokeSnapshotJob()
9521018
// InvokeConcatJob()
@@ -965,5 +1031,7 @@ func main() {
9651031
// InvokeSuperResolutionJob()
9661032
// TriggerWorkflow()
9671033
// DescribeWorkflowExecutions()
968-
DescribeMultiWorkflowExecution()
1034+
// DescribeMultiWorkflowExecution()
1035+
//InvokeASRJob()
1036+
DescribeASRJob()
9691037
}

0 commit comments

Comments
 (0)