fix: 修复上游省略event字段导致音频帧被丢弃的bug
This commit is contained in:
@@ -105,9 +105,26 @@ func ParseStream(body io.Reader, started time.Time) (*ParsedStream, error) {
|
|||||||
gotFirstChunk = true
|
gotFirstChunk = true
|
||||||
}
|
}
|
||||||
case "":
|
case "":
|
||||||
// 无 event 字段的元数据行(上游 TTSSentenceStart 偶发省略 event),
|
// 上游 v3 有时会省略 event 字段,音频数据直接出现在无 event 的行里;
|
||||||
// debug 模式打印便于排查;正常情况静默跳过。
|
// 只要 data 非空就当作音频帧解码收集。
|
||||||
if common.DebugLog && resp.Code == 0 {
|
if resp.Data != "" {
|
||||||
|
chunk, err := base64.StdEncoding.DecodeString(resp.Data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &UpstreamError{
|
||||||
|
Code: resp.Code,
|
||||||
|
Message: fmt.Sprintf("decode audio chunk: %v", err),
|
||||||
|
Stage: "stream",
|
||||||
|
Wrapped: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.AudioData = append(out.AudioData, chunk...)
|
||||||
|
out.Chunks++
|
||||||
|
if !gotFirstChunk {
|
||||||
|
out.FirstChunk = time.Since(started)
|
||||||
|
gotFirstChunk = true
|
||||||
|
}
|
||||||
|
} else if common.DebugLog && resp.Code == 0 {
|
||||||
|
// 元数据行(无 data 无 event),debug 模式打印便于排查
|
||||||
log.Printf("volcano: 无 event 字段 code=%d sequence=%d sentence=%s data_len=%d", resp.Code, resp.Sequence, resp.SentenceText(), len(resp.Data))
|
log.Printf("volcano: 无 event 字段 code=%d sequence=%d sentence=%s data_len=%d", resp.Code, resp.Sequence, resp.SentenceText(), len(resp.Data))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user