Skip to content
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

Merged
merged 11 commits into from
Jul 16, 2022

Conversation

PickledChair
Copy link
Member

@PickledChair PickledChair commented Jul 16, 2022

内容

voicevox_ttsvoicevox_wav_free を実装します。
ビルド結果のコアを cpp example で呼び出せることを確認していますが、wav 自体は出力できる(wav ヘッダも問題ないように見える)ものの、音が鳴る wav を出力できていないので draft にしています。

ビルド結果のコアを cpp example から呼び出せます。おそらく期待通りに音声合成できていそうでした。

関連 Issue

ref #128

(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();
Copy link
Contributor

Choose a reason for hiding this comment

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

with_capacityを使ったほうが良いと思います

Copy link
Member Author

Choose a reason for hiding this comment

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

そうですね! with_capacity で必要な大きさを事前確保するように修正しました。

@qwerty2501
Copy link
Contributor

そもそも yukarin_s_forward,yukarin_sa_forward,decode_forwardはまともに動かせるか確認取れてるんでしたっけ

output_wav: *const *mut u8,
) -> Result<()> {
unimplemented!()
pub fn voicevox_tts(&mut self, text: &CStr, speaker_id: usize) -> Result<Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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じゃなくても良さそうですね

Copy link
Member Author

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 に変えました)

@PickledChair
Copy link
Member Author

PickledChair commented Jul 16, 2022

そもそも yukarin_s_forward,yukarin_sa_forward,decode_forwardはまともに動かせるか確認取れてるんでしたっけ

voicevox_engine から正常に呼び出せる(再生可能な音声を取得できる)ことを手元で確認しているので、大丈夫のはずです!

今バグを発見しており、修正にかかっています(full_context_label::string_feature_by_regex 関数が期待通りの結果を返していませんでした。また、他にもバグがあり、潰しにかかっています)。

@qwerty2501
Copy link
Contributor

full_context_label::string_feature_by_regex 関数が期待通りの結果を返していませんでした

あ、すみませんそのあたり実装急いでテスト書かなかったやつでした

@PickledChair
Copy link
Member Author

voicevox_tts 関数で音声合成できるようになりました

@PickledChair PickledChair marked this pull request as ready for review July 16, 2022 16:53
output_binary_size,
output_wav,
let (output_opt, result_code) = convert_result(lock_internal().voicevox_tts(
unsafe { CStr::from_ptr(text) }.to_str().unwrap(),
Copy link
Member Author

@PickledChair PickledChair Jul 16, 2022

Choose a reason for hiding this comment

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

ここも to_str でパニックにせずエラーハンドリングした方が良いでしょうか?

Copy link
Contributor

@qwerty2501 qwerty2501 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Hiroshiba Hiroshiba left a 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();
Copy link
Member

Choose a reason for hiding this comment

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

別にこのままでも問題ないのですが、ENGINEに合わせるならカタカナのが合ってそうかもです。
(たぶん変換用mapが必要で変更業が大きくなるし、別PRのが良さそう!)

Copy link
Member Author

Choose a reason for hiding this comment

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

ENGINEに合わせるならカタカナのが合ってそうかもです。

すみません、単なる実装忘れでした!

テキストに変換する関数は既に存在している(以下リンク)ので、すぐに PR 出せそうな気がします……!

#[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();
Copy link
Member

Choose a reason for hiding this comment

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

ただのメモなのですが、リサンプリング(なかなか奥が深い)とかはこのライブラリの範疇にしないほうが良いかもと感じました。

@Hiroshiba Hiroshiba merged commit ce9d36b into VOICEVOX:rust Jul 16, 2022
qwerty2501 pushed a commit to qwerty2501/voicevox_core that referenced this pull request Jul 23, 2022
* 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文字列としてデコードできない場合のエラーをハンドリングする
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants