Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosshi999 committed Oct 15, 2024
1 parent ccf2bd9 commit ba99e73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pub use crate::{
engine::open_jtalk::blocking::OpenJtalk, infer::runtimes::onnxruntime::blocking::Onnxruntime,
synthesizer::blocking::Synthesizer, synthesizer::blocking::Audio, user_dict::dict::blocking::UserDict,
voice_model::blocking::VoiceModelFile,
synthesizer::blocking::Audio, synthesizer::blocking::Synthesizer,
user_dict::dict::blocking::UserDict, voice_model::blocking::VoiceModelFile,
};

pub mod onnxruntime {
Expand Down
21 changes: 13 additions & 8 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub(crate) mod blocking {

/// 音声波形を生成する
pub fn render(&self, audio: &Audio, begin: usize, end: usize) -> Result<Vec<u8>> {
const MARGIN: usize = 14; // 使われているHifiGANのreceptive fieldから計算される安全マージン
const MARGIN: usize = 14; // 使われているHifiGANのreceptive fieldから計算される安全マージン
use std::cmp::min;
// 実態(workaround paddingを含まない)上での区間
let clipped_begin = min(begin, audio.length);
Expand All @@ -510,13 +510,18 @@ pub(crate) mod blocking {
// 安全マージンを追加したデータ上での区間
let slice_begin = audio.padding_length + clipped_begin - left_margin;
let slice_end = audio.padding_length + clipped_end + right_margin;
let window = audio.internal_state.slice(ndarray::s![slice_begin..slice_end, ..]);
let wave_with_margin = self.render_audio_segment(window.into_owned(), audio.style_id)?;
let wave = wave_with_margin.slice(ndarray::s![left_margin*256..wave_with_margin.len()-right_margin*256]).into_owned().into_raw_vec();
return Ok(to_s16le_pcm(
&wave,
&audio.audio_query,
));
let window = audio
.internal_state
.slice(ndarray::s![slice_begin..slice_end, ..]);
let wave_with_margin =
self.render_audio_segment(window.into_owned(), audio.style_id)?;
let wave = wave_with_margin
.slice(ndarray::s![
left_margin * 256..wave_with_margin.len() - right_margin * 256
])
.into_owned()
.into_raw_vec();
return Ok(to_s16le_pcm(&wave, &audio.audio_query));

fn to_s16le_pcm(
wave: &[f32],
Expand Down
10 changes: 3 additions & 7 deletions crates/voicevox_core_python_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ mod blocking {
pub(crate) struct Audio {
audio: voicevox_core::blocking::Audio,
}

#[pymethods]
impl Audio {
#[getter]
Expand Down Expand Up @@ -684,7 +684,7 @@ mod blocking {
},
)
.into_py_result(py)?;
Ok(Audio {audio})
Ok(Audio { audio })
}

#[pyo3(signature=(
Expand All @@ -702,11 +702,7 @@ mod blocking {
let wav = &self
.synthesizer
.read()?
.render(
&audio.audio,
begin,
end,
)
.render(&audio.audio, begin, end)
.into_py_result(py)?;
Ok(PyBytes::new(py, wav))
}
Expand Down

0 comments on commit ba99e73

Please sign in to comment.