-
Notifications
You must be signed in to change notification settings - Fork 121
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
kana_parser 実装 #155
kana_parser 実装 #155
Conversation
元がengineディレクトリ切ってるのでそれに寄せてengine module作ったほうが良いと思います |
エラーを独自型にした理由ってなんかあったりするんですか? |
一旦書き写すにあたって閉じたモジュールにしたかったためです。TTS機能の実装ももう少し先になりそうなのでそのときに対応させればいいかなと思っていました。 例えばTTS系統のエラーはcoreとは別に型を作ってまとめる、みたいなことも将来的にあるかな、と想像しています |
@nebocco PR ありがとうございます! 細かいところは後で詳しく見てみたいと思います。 プロジェクトの構成については @qwerty2501 さんの意見
に同意で、例えば
みたいな構造にするのが良いのかな、と思いました! |
あ!! |
すみません、間違えました🙇♂️ |
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.
とりあえずテスト以外のコードをレビューしました(すみません、テストコードはまた後ほどレビューします……!)。確認よろしくお願いいたします。
@PickledChair |
@Hiroshiba |
ひとまずいただいたレビューのうち以下の二点以外を修正しました。 |
TTS用のクレート分割は後のタイミングで大丈夫だと思います! |
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.
申し訳ありません、なかなかレビューの時間が取れず、かなりお待たせしてしまいました……! テストコードについてもレビューしました。確認よろしくお願いします。
他の Rust 実装関連の PR がいくつかマージされ、おそらくコンフリクトが発生しているので、Draft を外す際は解消をよろしくお願いいたします……!
レビューありがとうございました。ご指摘いただいた点を修正いたしました。 |
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.
すみません、前回のレビューが中途半端な書き方になってしまい、少し意図が伝わらなかった部分があったようなので、追加の change request を出しました(rstest を使うように書いたことについてなのですが、機能的に便利だから使うということの他に、voicevox_core クレートのテストが基本的に全て rstest を使って書かれており、可読性を上げるために全てのテストで rstest を似たような形式で用いたい、という意図があってコメントしていました。わかりづらくて申し訳ありませんでした……!)。
#[derive(Clone, Debug)] | ||
pub(super) struct MoraModel { | ||
pub text: String, | ||
pub consonant: Option<String>, | ||
pub consonant_length: Option<f32>, | ||
pub vowel: String, | ||
pub vowel_length: f32, | ||
pub pitch: f32, | ||
} | ||
|
||
#[allow(dead_code)] // TODO: remove this feature | ||
#[derive(Debug)] | ||
pub(super) struct AccentPhraseModel { | ||
pub moras: Vec<MoraModel>, | ||
pub accent: usize, | ||
pub pause_mora: Option<MoraModel>, | ||
pub is_interrogative: bool, | ||
} | ||
|
||
#[allow(dead_code)] // TODO: remove this feature | ||
pub(super) struct AudioQueryModel { | ||
accent_phrases: Vec<AccentPhraseModel>, | ||
speed_scale: f32, | ||
pitch_scale: f32, | ||
intonation_scale: f32, | ||
volume_scale: f32, | ||
pre_phoneme_length: f32, | ||
post_phoneme_length: f32, | ||
output_sampling_rate: u32, | ||
output_stereo: bool, | ||
kana: String, | ||
} |
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.
いったんderive_newとderive_getters使ってみようという方針になっていたはずなので各structにdrive(new,Getter)をしてfieldのpubを外してstructのimmutable性を高めたほうが良いと思います
#[derive(Clone, Debug)] | |
pub(super) struct MoraModel { | |
pub text: String, | |
pub consonant: Option<String>, | |
pub consonant_length: Option<f32>, | |
pub vowel: String, | |
pub vowel_length: f32, | |
pub pitch: f32, | |
} | |
#[allow(dead_code)] // TODO: remove this feature | |
#[derive(Debug)] | |
pub(super) struct AccentPhraseModel { | |
pub moras: Vec<MoraModel>, | |
pub accent: usize, | |
pub pause_mora: Option<MoraModel>, | |
pub is_interrogative: bool, | |
} | |
#[allow(dead_code)] // TODO: remove this feature | |
pub(super) struct AudioQueryModel { | |
accent_phrases: Vec<AccentPhraseModel>, | |
speed_scale: f32, | |
pitch_scale: f32, | |
intonation_scale: f32, | |
volume_scale: f32, | |
pre_phoneme_length: f32, | |
post_phoneme_length: f32, | |
output_sampling_rate: u32, | |
output_stereo: bool, | |
kana: String, | |
} | |
#[derive(Clone, Debug, new, Getter)] | |
pub(super) struct MoraModel { | |
text: String, | |
consonant: Option<String>, | |
consonant_length: Option<f32>, | |
vowel: String, | |
vowel_length: f32, | |
pitch: f32, | |
} | |
#[allow(dead_code)] // TODO: remove this feature | |
#[derive(Debug, new, Getter)] | |
pub(super) struct AccentPhraseModel { | |
moras: Vec<MoraModel>, | |
accent: usize, | |
pause_mora: Option<MoraModel>, | |
is_interrogative: bool, | |
} | |
#[allow(dead_code)] // TODO: remove this feature | |
#[derive(new, Getter)] | |
pub(super) struct AudioQueryModel { | |
accent_phrases: Vec<AccentPhraseModel>, | |
speed_scale: f32, | |
pitch_scale: f32, | |
intonation_scale: f32, | |
volume_scale: f32, | |
pre_phoneme_length: f32, | |
post_phoneme_length: f32, | |
output_sampling_rate: u32, | |
output_stereo: bool, | |
kana: String, | |
} |
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.
とりあえず new と Getters を追加したのですが、ごく一部の属性は mutable に扱うことがあるため、最低限の広さで public としてみました。
voicevox_core/crates/voicevox_core/src/engine/kana_parser.rs
Lines 151 to 162 in 42e6cfd
let accent_phrase = { | |
let mut accent_phrase = text_to_accent_phrase(&phrase)?; | |
if letter == PAUSE_DELIMITER { | |
accent_phrase.pause_mora = Some(MoraModel::new( | |
PAUSE_DELIMITER.to_string(), | |
None, | |
None, | |
"pau".to_string(), | |
)); | |
} | |
accent_phrase.is_interrogative = is_interrogative; | |
accent_phrase |
voicevox_core/crates/voicevox_core/src/engine/model.rs
Lines 17 to 24 in 42e6cfd
#[allow(dead_code)] // TODO: remove this feature | |
#[derive(Debug, new, Getters)] | |
pub(super) struct AccentPhraseModel { | |
moras: Vec<MoraModel>, | |
accent: usize, | |
pub(super) pause_mora: Option<MoraModel>, | |
pub(super) is_interrogative: bool, | |
} |
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.
accessibilityを変えるのではなく、必要な部分にだけsetterをAccentPhraseModel に生やすように出来ますか?
機能上全てのフィールドを初期化後に変更する可能性があるのであればGettersを使わずに初めからpublicにしたほうがよいですが、今回のように部分的に変更するのであればsetterが良いと思います
fix: use rstest Co-authored-by: Gray Suitcase <[email protected]>
Co-authored-by: qwerty2501 <[email protected]>
Co-authored-by: Gray Suitcase <[email protected]>
Co-authored-by: Gray Suitcase <[email protected]>
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! PR ありがとうございました。長いレビュー期間になってしまい大変お待たせしてしまいました。お疲れ様でした!
#155 (comment) への対応に関して、 @qwerty2501 さんが特に問題ないという感じでしたらマージで良いと思います!
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
PRありがとうございました!! |
* WIP: kana parser * add: parse_kana/create_kana * add: error handling, tests * fix: removed unused #[derive()] * fix: cargo clippy * modify: modified directory layout * fmt: cargo fmt * fixx: mistake * modify: module layout * fix: reflect reviews * fix: use hashMap instead of BTreeMap * change: use rstest for mod tests * Update crates/voicevox_core/src/engine/kana_parser.rs fix: use rstest Co-authored-by: Gray Suitcase <[email protected]> * update: use #[derive(new, Getter)] Co-authored-by: qwerty2501 <[email protected]> * fix: use rstest Co-authored-by: Gray Suitcase <[email protected]> * fix: use rstest Co-authored-by: Gray Suitcase <[email protected]> * fix: use new() and getters * fmt: clippy * update: define setters for requiring attrs Co-authored-by: Gray Suitcase <[email protected]> Co-authored-by: qwerty2501 <[email protected]>
内容
core/src/engine/mora_list.cpp, kana_parser.cpp の内容を Rust で実装しました。
関連 Issue
ref #128
その他
存在する関数を一通り実装し、簡単なテストを書きました。とりあえずこれ自体で機能が完結しているものを作ろうとしたので、以下のような修正点・調整点が残っています。
また、C++ での実装で計算量の悪い箇所がありましたがそのまま残しています。