Skip to content

Commit

Permalink
margin validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosshi999 committed Oct 26, 2024
1 parent abdc696 commit 6e41b94
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,18 @@ pub(crate) mod blocking {
if (clipped_start..clipped_end).is_empty() {
return Ok(vec![]);
}
// データからはみ出さない安全マージン
let left_margin = min(MARGIN, audio.padding_frame_length + clipped_start);
let right_margin = min(
MARGIN,
audio.padding_frame_length + (audio.frame_length - clipped_end),
);
// マージンがデータからはみ出さないことを保証
// cf. https://github.com/VOICEVOX/voicevox_core/pull/854#discussion_r1803691291
if (MARGIN > audio.padding_frame_length + clipped_start
|| MARGIN > audio.padding_frame_length + (audio.frame_length - clipped_end))
{
return Err(ErrorRepr::RunModel(anyhow::anyhow!(
"Validation error: Too short padding for input"
))
.into());
}
let left_margin = MARGIN;
let right_margin = MARGIN;
// 安全マージンを追加したデータ上での区間
let slice_start = audio.padding_frame_length + clipped_start - left_margin;
let slice_end = audio.padding_frame_length + clipped_end + right_margin;
Expand Down

0 comments on commit 6e41b94

Please sign in to comment.