-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Rust] voicevox_tts と voicevox_wav_free の実装 #186
[Rust] voicevox_tts と voicevox_wav_free の実装 #186
Conversation
(output_sampling_rate / Self::DEFAULT_SAMPLING_RATE) * num_channels as u32; | ||
let block_size: u16 = bit_depth * num_channels / 8; | ||
|
||
let buf: Vec<u8> = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_capacityを使ったほうが良いと思います
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね! with_capacity
で必要な大きさを事前確保するように修正しました。
そもそも yukarin_s_forward,yukarin_sa_forward,decode_forwardはまともに動かせるか確認取れてるんでしたっけ |
crates/voicevox_core/src/internal.rs
Outdated
output_wav: *const *mut u8, | ||
) -> Result<()> { | ||
unimplemented!() | ||
pub fn voicevox_tts(&mut self, text: &CStr, speaker_id: usize) -> Result<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn voicevox_tts(&mut self, text: &CStr, speaker_id: usize) -> Result<Vec<u8>> { | |
pub fn voicevox_tts(&mut self, text: &str, speaker_id: usize) -> Result<Vec<u8>> { |
ここはCStrじゃなくても良さそうですね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&str
にしました!(ついでに Internal::voicevox_load_openjtalk_dict
の引数の &CStr
も &str
に変えました)
voicevox_engine から正常に呼び出せる(再生可能な音声を取得できる)ことを手元で確認しているので、大丈夫のはずです! 今バグを発見しており、修正にかかっています( |
あ、すみませんそのあたり実装急いでテスト書かなかったやつでした |
|
crates/voicevox_core/src/c_export.rs
Outdated
output_binary_size, | ||
output_wav, | ||
let (output_opt, result_code) = convert_result(lock_internal().voicevox_tts( | ||
unsafe { CStr::from_ptr(text) }.to_str().unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも to_str
でパニックにせずエラーハンドリングした方が良いでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
処理を細かく読んでみました。たぶん問題ない・・・はず・・・!
念の為にENGINEの出力と一致するか確かめておきたいなーと思いました!
.map(|phoneme| phoneme.phoneme().to_string()) | ||
.collect::<Vec<_>>() | ||
.join(""); | ||
mora_text = mora_text.to_lowercase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
別にこのままでも問題ないのですが、ENGINEに合わせるならカタカナのが合ってそうかもです。
(たぶん変換用mapが必要で変更業が大きくなるし、別PRのが良さそう!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENGINEに合わせるならカタカナのが合ってそうかもです。
すみません、単なる実装忘れでした!
テキストに変換する関数は既に存在している(以下リンク)ので、すぐに PR 出せそうな気がします……!
voicevox_core/crates/voicevox_core/src/engine/mora_list.rs
Lines 189 to 200 in ce9d36b
#[allow(dead_code)] // TODO: remove this feature | |
fn mora2text(mora: &str) -> &str { | |
for &[text, consonant, vowel] in MORA_LIST_MINIMUM { | |
if mora.len() >= consonant.len() | |
&& &mora[..consonant.len()] == consonant | |
&& &mora[consonant.len()..] == vowel | |
{ | |
return text; | |
} | |
} | |
mora | |
} |
let volume_scale = *query.volume_scale(); | ||
let output_stereo = *query.output_stereo(); | ||
// TODO: 44.1kHzなどの対応 | ||
let output_sampling_rate = *query.output_sampling_rate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただのメモなのですが、リサンプリング(なかなか奥が深い)とかはこのライブラリの範疇にしないほうが良いかもと感じました。
* implements create_accent_phrases * implements synthesis * implements synthesis_wave_format * implements voicevox_tts and voicevox_wav_free * resolve clippy warning * 音声合成できるように修正 * wavのためのバッファのvecをwith_capacityでメモリ確保 * Internalのメソッドの引数としてCStrの代わりにstrを使う * Dissolveを使わない * UTF-8文字列としてデコードできない場合のエラーをハンドリングする
内容
voicevox_tts
とvoicevox_wav_free
を実装します。ビルド結果のコアを cpp example で呼び出せることを確認していますが、wav 自体は出力できる(wav ヘッダも問題ないように見える)ものの、音が鳴る wav を出力できていないので draft にしています。ビルド結果のコアを cpp example から呼び出せます。おそらく期待通りに音声合成できていそうでした。
関連 Issue
ref #128