fix(asr): 一句话识别 sourceType=1 时支持显式 voiceFormat(test-0415 反馈3-1 续修)

- 老逻辑:req.setVoiceFormat(getVoiceFormat(request.getUrl()))
  sourceType=1 时 url 为空 → 默认 wav → 把 mp3 数据当 wav 给腾讯云 → "Audio decoding failed"
- 修复:TencentAsrRequest 新增 voiceFormat 字段(前端已透传 'mp3')
  ToolTencentAsrServiceImpl.sentenceRecognition 优先使用 request.getVoiceFormat(),
  缺省回落到 getVoiceFormat(url) 兼容老调用

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
msh-agent
2026-05-03 03:05:37 +08:00
parent 276366f98e
commit e27e094183
2 changed files with 10 additions and 1 deletions

View File

@@ -50,4 +50,7 @@ public class TencentAsrRequest {
@ApiModelProperty(value = "是否显示词级别时间戳")
private Boolean wordInfo;
@ApiModelProperty(value = "音频格式sourceType=1 时必传mp3/wav/m4a/aac/pcm/silk", example = "mp3")
private String voiceFormat;
}

View File

@@ -179,7 +179,13 @@ public class ToolTencentAsrServiceImpl implements ToolTencentAsrService {
request.getEngineModelType() : asrConfig.getDefaultEngineModel());
req.setSourceType(request.getSourceType() != null ?
request.getSourceType().longValue() : 0L);
req.setVoiceFormat(getVoiceFormat(request.getUrl()));
// test-0415 反馈3-1sourceType=1 时 url 为空,从 url 推断会默认 wav导致 mp3 数据被当 wav 解 → "Audio decoding failed"
// 优先使用前端显式传入的 voiceFormat
String voiceFormat = request.getVoiceFormat();
if (voiceFormat == null || voiceFormat.isEmpty()) {
voiceFormat = getVoiceFormat(request.getUrl());
}
req.setVoiceFormat(voiceFormat);
if (request.getSourceType() != null && request.getSourceType() == 1) {
req.setData(request.getData());