-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ストリーミングモードのdecodeを実装(precompute_renderとrender) (#854)
この本文は @qryxip が記述している。 #851 で生まれた`generate_full_intermediate`と`render_audio_segment`を用 いて次の公開APIを作る。`precompute_render`で`AudioFeature`を生成し、 `AudioFeature`と区間指定を引数とした`render`で指定区間のPCMを生成する 形。 - `voicevox_core::blocking::Synthesizer::precompute_render` - `voicevox_core::blocking::Synthesizer::render` - `voicevox_core::blocking::AudioFeature` また`render`で生成したPCMをWAVとして組み立てるため、次の公開APIも作る。 - `voicevox_core::wav_from_s16le` ただしこのPRで実装するのはRust APIとPython APIのみ。非同期API、C API、 Java APIについては今後実装する。Python APIのtype stubも今後用意する。ま たテストも今後書く。 Refs: #853 Co-authored-by: Ryo Yamashita <[email protected]> Co-authored-by: Hiroshiba <[email protected]> Co-authored-by: Nanashi. <[email protected]>
- Loading branch information
1 parent
fdae73a
commit 5641e37
Showing
9 changed files
with
352 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::io::{Cursor, Write as _}; | ||
|
||
/// 16bit PCMにヘッダを付加しWAVフォーマットのバイナリを生成する。 | ||
pub fn wav_from_s16le(pcm: &[u8], sampling_rate: u32, is_stereo: bool) -> Vec<u8> { | ||
let num_channels: u16 = if is_stereo { 2 } else { 1 }; | ||
let bit_depth: u16 = 16; | ||
let block_size: u16 = bit_depth * num_channels / 8; | ||
|
||
let bytes_size = pcm.len() as u32; | ||
let wave_size = bytes_size + 44; | ||
|
||
let buf: Vec<u8> = Vec::with_capacity(wave_size as usize); | ||
let mut cur = Cursor::new(buf); | ||
|
||
cur.write_all("RIFF".as_bytes()).unwrap(); | ||
cur.write_all(&(wave_size - 8).to_le_bytes()).unwrap(); | ||
cur.write_all("WAVEfmt ".as_bytes()).unwrap(); | ||
cur.write_all(&16_u32.to_le_bytes()).unwrap(); // fmt header length | ||
cur.write_all(&1_u16.to_le_bytes()).unwrap(); // linear PCM | ||
cur.write_all(&num_channels.to_le_bytes()).unwrap(); | ||
cur.write_all(&sampling_rate.to_le_bytes()).unwrap(); | ||
|
||
let block_rate = sampling_rate * block_size as u32; | ||
|
||
cur.write_all(&block_rate.to_le_bytes()).unwrap(); | ||
cur.write_all(&block_size.to_le_bytes()).unwrap(); | ||
cur.write_all(&bit_depth.to_le_bytes()).unwrap(); | ||
cur.write_all("data".as_bytes()).unwrap(); | ||
cur.write_all(&bytes_size.to_le_bytes()).unwrap(); | ||
cur.write_all(pcm).unwrap(); | ||
cur.into_inner() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.