Skip to content

fix: 修复 TTS 音频后处理中的关键缺陷(int16 溢出 / padding_len=0 / 异常类型)#2753

Merged
RVC-Boss merged 1 commit intoRVC-Boss:mainfrom
wishhyt:fix/tts-audio-postprocess
Apr 18, 2026
Merged

fix: 修复 TTS 音频后处理中的关键缺陷(int16 溢出 / padding_len=0 / 异常类型)#2753
RVC-Boss merged 1 commit intoRVC-Boss:mainfrom
wishhyt:fix/tts-audio-postprocess

Conversation

@wishhyt
Copy link
Copy Markdown
Contributor

@wishhyt wishhyt commented Mar 18, 2026

问题描述

GPT_SoVITS/TTS_infer_pack/TTS.pyaudio_postprocess 方法中发现三个 bug:

1. [CRITICAL] 音频超采样时 int16 双重转换导致整数溢出

第 1590 行 audio = (audio * 32768).astype(np.int16) 位于 if super_sampling / else 块之外,无条件执行。

super_sampling=True 时:

  • 第 1581 行已将音频转为 int16(值域 -32768~32767)
  • 第 1590 行再次乘以 32768 → 整数溢出 → 输出音频完全失真

此外,当 super_sampling=True 但超分模型文件不存在时,audio 仍为 torch.Tensor
调用 .astype() 会抛出 AttributeError

2. [HIGH] padding_len=0 时 batched vocoder 推理音频丢失

batched_decode 方法中,当最后一个 chunk 刚好填满(padding_len == 0)时:
-0 * upsample_rate == 0,切片变为 audio[x:0],返回空张量,导致整段音频丢失。

3. [LOW] 文件不存在时错误地抛出 FileExistsError

第 502 行在 LoRA 底模文件不存在时抛出 FileExistsError,应为 FileNotFoundError

修改内容

  • 将无条件的 int16 转换移入各分支内部,分别处理超分模型存在/不存在的情况
  • padding_len == 0 增加条件判断,避免空切片
  • 修正异常类型

测试方案

  • 开启 super_sampling=True 进行 TTS 推理,验证音频输出正常
  • 使用长度恰好对齐的文本测试 padding_len=0 边界条件
  • 在缺少 LoRA 底模时触发加载,验证异常类型正确

1. 修复音频超采样时 int16 双重转换导致整数溢出(CRITICAL)
   - audio_postprocess 中 `audio = (audio * 32768).astype(np.int16)` 位于
     if/else 块之外无条件执行,当 super_sampling=True 时音频已在分支内
     转为 int16,再次乘以 32768 导致溢出和音频完全失真
   - 同时修复 super_sampling=True 但超分模型不存在时 torch.Tensor 调用
     .astype() 的 AttributeError

2. 修复 batched vocoder 推理中 padding_len=0 导致音频丢失(HIGH)
   - 当 padding_len 恰好为 0 时,`-0 * upsample_rate == 0`,切片
     `audio[x:0]` 返回空张量,导致整段音频丢失

3. 修复文件不存在时错误地抛出 FileExistsError(LOW)
   - 应为 FileNotFoundError

Made-with: Cursor
@RVC-Boss RVC-Boss merged commit 445d18c into RVC-Boss:main Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants