Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sherpa-onnx/csrc/offline-tts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ GeneratedAudio GeneratedAudio::ScaleSilence(float scale) const {
if (scale == 1) {
return *this;
}

// scale is used to shorten long pauses, so it is normally within (0, 1).
// Values outside this range are rejected: n below is computed as
// interval_length * scale and converted to an int32_t, and NaN, infinity or
// a very large scale make that conversion undefined. Note that any
// comparison with NaN is false, so NaN is rejected here as well.
if (!(scale >= 0.01f && scale <= 2.0f)) {
SHERPA_ONNX_LOGE("Silence scale %f is not in [0.01, 2]. Skip scaling.",
scale);
return *this;
}
Comment on lines +44 to +48

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Config validation range [0.001, ∞) doesn't match ScaleSilence range [0.01, 2.0].

OfflineTtsConfig::Validate() at line 224 only rejects silence_scale < 0.001 with no upper bound, but ScaleSilence rejects values outside [0.01, 2.0]. Values in [0.001, 0.01) or above 2.0 pass config validation but are silently no-op'd at runtime — the user gets unscaled audio with no indication beyond a log message.

Align the two ranges to avoid surprising behavior:

🔧 Proposed fix for Validate()
-  if (silence_scale < 0.001) {
-    SHERPA_ONNX_LOGE("--tts-silence-scale '%.3f' is too small", silence_scale);
+  if (silence_scale < 0.01f || silence_scale > 2.0f) {
+    SHERPA_ONNX_LOGE("--tts-silence-scale '%.3f' is not in [0.01, 2]",
+                     silence_scale);
     return false;
   }

Also applies to: 224-227

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sherpa-onnx/csrc/offline-tts.cc` around lines 44 - 48, Align
OfflineTtsConfig::Validate() with ScaleSilence by validating silence_scale
within the inclusive range [0.01, 2.0], rejecting values below 0.01 or above 2.0
and reporting the validation error consistently. Update the existing
silence_scale validation logic in OfflineTtsConfig::Validate() so all values
accepted by configuration are handled by ScaleSilence without being silently
skipped.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Range check rejects scale = 0, breaking existing pause-removal behavior.

The PR summary states "Scale 0 retains its existing behavior of removing pauses," but 0 < 0.01f fails the range check, so ScaleSilence(0) now logs an error and returns unscaled audio with pauses intact. Previously, scale = 0 produced n = 0, effectively removing all silence intervals.

If scale = 0 should still remove pauses, lower the bound to 0.0f:

🔧 Proposed fix
-  if (!(scale >= 0.01f && scale <= 2.0f)) {
-    SHERPA_ONNX_LOGE("Silence scale %f is not in [0.01, 2]. Skip scaling.",
+  if (!(scale >= 0.0f && scale <= 2.0f)) {
+    SHERPA_ONNX_LOGE("Silence scale %f is not in [0, 2]. Skip scaling.",
                      scale);

If rejecting scale = 0 is intentional, the PR summary should be corrected to reflect this behavior change.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!(scale >= 0.01f && scale <= 2.0f)) {
SHERPA_ONNX_LOGE("Silence scale %f is not in [0.01, 2]. Skip scaling.",
scale);
return *this;
}
if (!(scale >= 0.0f && scale <= 2.0f)) {
SHERPA_ONNX_LOGE("Silence scale %f is not in [0, 2]. Skip scaling.",
scale);
return *this;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sherpa-onnx/csrc/offline-tts.cc` around lines 44 - 48, Update the range
validation in ScaleSilence to allow scale = 0 by changing the lower bound from
0.01f to 0.0f, preserving the existing behavior that removes silence intervals
when scaling by zero.

// if the interval is larger than 0.2 second, then we assume it is a pause
int32_t threshold = static_cast<int32_t>(sample_rate * 0.2);

Expand Down
Loading