@@ -57,7 +57,7 @@ func (s *Speech) Recognize(ctx context.Context, fileUri string) (sRet []*srt.Srt
57
57
if err != nil {
58
58
return
59
59
}
60
- logrus .Info ("aliyun speech add task %s" ,fileUri )
60
+ logrus .Infof ("aliyun speech add task %s" ,fileUri )
61
61
taskId , err = s .sendTask (client , fileUri )
62
62
if err != nil {
63
63
return
@@ -67,11 +67,11 @@ func (s *Speech) Recognize(ctx context.Context, fileUri string) (sRet []*srt.Srt
67
67
if err != nil || rsp == nil {
68
68
return
69
69
}
70
- logrus .Infof ("aliyun speech recognize result [%d]" ,len (rsp .Result .Sentences ))
71
70
if rsp .StatusText != STATUS_SUCCESS {
72
71
err = errors .WithMessage (err , "recognize failed" )
73
72
return
74
73
}
74
+ logrus .Infof ("aliyun speech recognize result [%d]" ,len (rsp .Result .Sentences ))
75
75
sRet , err = s .Sentence (0 , rsp )
76
76
wRet , err = s .BreakSentence (0 , rsp )
77
77
if err != nil {
@@ -217,7 +217,14 @@ func (s *Speech) BreakSentence(channelId int, rsp *Response) (ret []*srt.Srt, er
217
217
sword = strings .TrimRight (sword , text .SentenceBreak )
218
218
}
219
219
220
- sword = strings .ToLower (strings .TrimSpace (sword ))
220
+ sword = strings .ToLower (strings .TrimFunc (strings .TrimSpace (sword ), func (r rune ) bool {
221
+ if strings .ContainsRune (text .SentenceBreak ,r ){
222
+ return true
223
+ }else {
224
+ return false
225
+ }
226
+ return false
227
+ }))
221
228
222
229
numberFlag := false
223
230
firstSetFlag := true
@@ -226,8 +233,8 @@ func (s *Speech) BreakSentence(channelId int, rsp *Response) (ret []*srt.Srt, er
226
233
if rsp .Result .Words [wIdx ].ChannelId != channelId {
227
234
continue
228
235
}
229
-
230
236
word := strings .ToLower (strings .TrimSpace (rsp .Result .Words [wIdx ].Word ))
237
+ fmt .Printf ("%s:%s\n " ,word ,sword )
231
238
//当前单词是数字,并且句子中的词也是数字
232
239
if v , ok := s .wellKnownNumber [word ]; ok && re .Match ([]byte (sword )) {
233
240
numberFlag = true
0 commit comments