From c8f5c3a02dd692a5c4fc250ed392dd1bc3b8a4a1 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 1 Dec 2023 14:56:28 +0900 Subject: [PATCH] =?UTF-8?q?dataclass=E3=81=A7=E3=82=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=8A=E3=83=AB=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=81=B9=E3=81=8D=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=82=92=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=8A=E3=83=AB=E3=81=AB=E3=81=99=E3=82=8B=20(#696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/engine/model.rs | 29 ++++++++++++++ .../python/test/test_audio_query.py | 38 +++++++++++++++++++ .../python/voicevox_core/_models.py | 18 ++++----- 3 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 crates/voicevox_core_python_api/python/test/test_audio_query.py diff --git a/crates/voicevox_core/src/engine/model.rs b/crates/voicevox_core/src/engine/model.rs index 657c3c232..26e34252c 100644 --- a/crates/voicevox_core/src/engine/model.rs +++ b/crates/voicevox_core/src/engine/model.rs @@ -87,6 +87,7 @@ mod tests { use super::*; use crate::*; use pretty_assertions::assert_eq; + use serde_json::json; #[rstest] fn check_audio_query_model_json_field_snake_case() { @@ -115,4 +116,32 @@ mod tests { _ => {} } } + + #[rstest] + fn it_accepts_json_without_optional_fields() -> anyhow::Result<()> { + serde_json::from_value::(json!({ + "accent_phrases": [ + { + "moras": [ + { + "text": "ア", + "vowel": "a", + "vowel_length": 0.0, + "pitch": 0.0 + } + ], + "accent": 1 + } + ], + "speed_scale": 1.0, + "pitch_scale": 0.0, + "intonation_scale": 1.0, + "volume_scale": 1.0, + "pre_phoneme_length": 0.1, + "post_phoneme_length": 0.1, + "output_sampling_rate": 24000, + "output_stereo": false + }))?; + Ok(()) + } } diff --git a/crates/voicevox_core_python_api/python/test/test_audio_query.py b/crates/voicevox_core_python_api/python/test/test_audio_query.py new file mode 100644 index 000000000..fc7133e1a --- /dev/null +++ b/crates/voicevox_core_python_api/python/test/test_audio_query.py @@ -0,0 +1,38 @@ +import json +import textwrap + +from voicevox_core import AudioQuery + + +def test_accept_json_without_optional_fields() -> None: + AudioQuery( + **json.loads( + textwrap.dedent( + """\ + { + "accent_phrases": [ + { + "moras": [ + { + "text": "ア", + "vowel": "a", + "vowel_length": 0.0, + "pitch": 0.0 + } + ], + "accent": 1 + } + ], + "speed_scale": 1.0, + "pitch_scale": 0.0, + "intonation_scale": 1.0, + "volume_scale": 1.0, + "pre_phoneme_length": 0.1, + "post_phoneme_length": 0.1, + "output_sampling_rate": 24000, + "output_stereo": false + } + """, + ) + ) + ) diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_models.py b/crates/voicevox_core_python_api/python/voicevox_core/_models.py index 89c1f3d37..195154629 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_models.py +++ b/crates/voicevox_core_python_api/python/voicevox_core/_models.py @@ -119,12 +119,6 @@ class Mora: text: str """文字。""" - consonant: Optional[str] - """子音の音素。""" - - consonant_length: Optional[float] - """子音の音長。""" - vowel: str """母音の音素。""" @@ -134,6 +128,12 @@ class Mora: pitch: float """音高。""" + consonant: Optional[str] = None + """子音の音素。""" + + consonant_length: Optional[float] = None + """子音の音長。""" + @pydantic.dataclasses.dataclass class AccentPhrase: @@ -145,10 +145,10 @@ class AccentPhrase: accent: int """アクセント箇所。""" - pause_mora: Optional[Mora] + pause_mora: Optional[Mora] = None """後ろに無音を付けるかどうか。""" - is_interrogative: bool + is_interrogative: bool = False """疑問系かどうか。""" @@ -183,7 +183,7 @@ class AudioQuery: output_stereo: bool """音声データをステレオ出力するか否か。""" - kana: Optional[str] # FIXME: requiredになっている(他の`Optional`も同様) + kana: Optional[str] = None """ [読み取り専用] AquesTalk風記法。