Skip to content

Commit e7911a3

Browse files
committed
fix:首词是数字情况下,start没赋值
1 parent d971c89 commit e7911a3

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

internal/text/aliyun/aliyun.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func (s *Speech) BreakSentence(channelId int, rsp *Response) (ret []*srt.Srt, er
242242
sword = strings.ToLower(strings.TrimSpace(sword))
243243

244244
numberFlag := false
245+
firstSetFlag := true
245246
for wIdx := curIdx; wIdx < len(rsp.Result.Words); wIdx++ {
246247
//更新curIdx
247248
if rsp.Result.Words[wIdx].ChannelId != channelId {
@@ -252,6 +253,11 @@ func (s *Speech) BreakSentence(channelId int, rsp *Response) (ret []*srt.Srt, er
252253
//当前单词是数字,并且句子中的词也是数字
253254
if v, ok := WellKnownNumber[word]; ok && re.Match([]byte(sword)) {
254255
numberFlag = true
256+
//如果首词是数字
257+
if swIdx == 0 && firstSetFlag {
258+
itr.Start = utils.MillisDurationConv(rsp.Result.Words[wIdx].BeginTime)
259+
firstSetFlag = false
260+
}
255261
itr.End = utils.MillisDurationConv(rsp.Result.Words[wIdx].EndTime)
256262
curIdx = wIdx + 1
257263
tmpNum, _ := strconv.Atoi(sword)

internal/text/aliyun/aliyun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818

1919
func TestSpeech_BreakSentence(t *testing.T) {
2020
rsp := &Response{}
21-
json.Unmarshal([]byte(result), rsp)
21+
json.Unmarshal([]byte(case1), rsp)
2222
sp := new(Speech)
2323
ret, err := sp.BreakSentence(0, rsp)
2424
if err != nil {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
var (
99
Major = 1
1010
Minor = 1
11-
Patch = 2
11+
Patch = 3
1212
)
1313

1414
func main() {

0 commit comments

Comments
 (0)