fix: 修复上游省略event字段导致音频帧被丢弃的bug

This commit is contained in:
sun
2026-08-16 17:50:02 +08:00
parent 55244e9a45
commit 677f606935
+20 -3
View File
@@ -105,9 +105,26 @@ func ParseStream(body io.Reader, started time.Time) (*ParsedStream, error) {
gotFirstChunk = true
}
case "":
// 无 event 字段的元数据行(上游 TTSSentenceStart 偶发省略 event),
// debug 模式打印便于排查;正常情况静默跳过。
if common.DebugLog && resp.Code == 0 {
// 上游 v3 有时会省略 event 字段,音频数据直接出现在无 event 的行里;
// 只要 data 非空就当作音频帧解码收集。
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))
}
default: