8000 [Rust] voicevox_tts_from_kana の実装 by PickledChair · Pull Request #193 · VOICEVOX/voicevox_core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Rust] voicevox_tts_from_kana の実装 #193

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

Merged

Conversation

PickledChair
Copy link
Member

内容

voicevox_tts_from_kana 関数を実装しました。

また、現段階の C++ 実装にある機能の再実装がこれでほぼ終わるので、clippy のエラーを抑制する目的で付けられていた #[allow(dead_code)] の対象を整理しました。

関連 Issue

ref #128

Comment on lines 297 to 302
unsafe {
output_binary_size.write(output.len() as c_int);
let wav_heap = libc::malloc(output.len());
libc::memcpy(wav_heap, output.as_ptr() as *const c_void, output.len());
output_wav.write(wav_heap as *mut u8);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[NITS] ここ voicevox_tts と処理が全く同じだと思うので共通化したほうがいいかもです

Copy link
Member Author

Choose a reason for hiding this comment

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

共通化しました!

@@ -54,6 +52,9 @@ pub enum Error {
base_error_message(VOICEVOX_RESULT_FAILED_EXTRACT_FULL_CONTEXT_LABEL)
)]
FailedExtractFullContextLabel(#[source] FullContextLabelError),

#[error("{},{0}", base_error_message(VOICEVOX_RESULT_FAILED_PARSE_KANA))]
FailedParseKana(#[source] KanaParseError),
Copy link
Contributor

Choose a reason for hiding this comment

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

ここの #[source] ですが、 #[from] にしておくとKanaParseErrorに対して?したときにFailedParseKanaに変換できるようになります
ここのmap_err とかは不要になります。
#[from] については Errorのenumのパターンと元になるErrorが1:1で対応してる時のみにしたほうがよいですが、これは1:1で対応できそうなのでやったほうがいいかもです(FailedExtractFullContextLabelも同じことが言えます。反対にGetSupportedDevicesが持っているSourceErrorについては他のパターンでも返ってくる可能性があるのでやめたほうが良いです。)

Copy link
Member Author

Choose a reason for hiding this comment

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

#[from] について失念していました(#[source] とごっちゃになってました……)。FailedExtractFullContextLabelFailedParseKana の両方について #[from] に変えました! 実際にエラーを変換している箇所についても、map_err せず単に ? 演算子だけで変換するように変更しました。

Comment on lines +522 to +524
VOICEVOX_RESULT_FAILED_PARSE_KANA => {
"入力テキストをAquesTalkライクな読み仮名としてパースすることに失敗しました\0"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ちょっと思ったんですが、エラーメッセージとエラーコードの名前対応してないのでは?
同様に voicevox_tts_from_kana という関数名では AquesTalkライクなテキストを期待することが使う側に伝えられてないように感じます。
今更という気もしますが

Copy link
Contributor
@qwerty2501 qwerty2501 Jul 20, 2022

Choose a reason for hiding this comment

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

あ、 voicevox_tts_from_kana についてはもう元から定義されてるから少なくとも今は変えないほうが良さそうですね

Copy link
Member
@Hiroshiba Hiroshiba Jul 20, 2022

Choose a reason for hiding this comment

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

ドメイン用語としては「AquesTalkライクな記法/読み仮名」で、コード上ではkanaという感じです。
AquesTalkという商品名を関数につけるのはうーんと思って、良い名前が思いつかず「kana」となった経緯があります。

個人的にはまあ良い名前思いつかないしkanaで良さそう、という気持ちです。

Copy link
Contributor

Choose a reason for hiding this comment

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

なるほどそうなるとKanaでいいのかもしれませんがちょっともやもやしますね。 🤔
しかしそういう理由だとメッセージにAquesTalkと入っているのは大丈夫でしょうか?

Copy link
Member

Choose a reason for hiding this comment

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

なんとかしたいと思いつつも、いったん大丈夫という判断で・・・!

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!!

いよいよですね!!!

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

@Hiroshiba Hiroshiba merged commit a6272c0 into VOICEVOX:rust Jul 20, 2022
qwerty2501 pushed a commit to qwerty2501/voicevox_core that referenced this pull request Jul 23, 2022
* implements voicevox_tts_from_kana

* allow dead_code をもう少し整理

* wavの書き込み処理を共通化

* FullContextLabelErrorとKanaParseErrorについて、fromでErrorに変換できるようにする
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.

3 participants
0