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

追加: engine_manifest.json をバリデーション #1295

Merged
merged 3 commits into from
May 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 44 additions & 1 deletion voicevox_engine/engine_manifest/EngineManifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@
from pydantic import BaseModel, Field


class FeatureSupportJson(BaseModel):
"""`engine_manifest.json` の機能サポート状況"""

type: str
value: bool
name: str


class SupportedFeaturesJson(BaseModel):
"""`engine_manifest.json` のサポート機能一覧"""

adjust_mora_pitch: FeatureSupportJson
adjust_phoneme_length: FeatureSupportJson
adjust_speed_scale: FeatureSupportJson
adjust_pitch_scale: FeatureSupportJson
adjust_intonation_scale: FeatureSupportJson
adjust_volume_scale: FeatureSupportJson
interrogative_upspeak: FeatureSupportJson
synthesis_morphing: FeatureSupportJson
sing: FeatureSupportJson
manage_library: FeatureSupportJson


class EngineManifestJson(BaseModel):
"""`engine_manifest.json` のコンテンツ"""

manifest_version: str
name: str
brand_name: str
uuid: str
version: str
url: str
command: str
port: int
icon: str
default_sampling_rate: int
frame_rate: float
terms_of_service: str
update_infos: str
dependency_licenses: str
supported_features: SupportedFeaturesJson


class UpdateInfo(BaseModel):
"""
エンジンのアップデート情報
Expand Down Expand Up @@ -78,7 +121,7 @@ def load_manifest(manifest_path: Path) -> EngineManifest:
"""エンジンマニフェストを指定ファイルから読み込む。"""

root_dir = manifest_path.parent
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
manifest = EngineManifestJson.parse_file(manifest_path).dict()
Copy link
Member

Choose a reason for hiding this comment

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

もしかしたらutf8読み込めなくなってるとかはあるかも…?
(parse fileの仕様によりそう)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

なるほどです。
最低限、今の ENGINE のマニフェストファイルは読めています。
ファイルの文字列エンコーディング周りはところどころ実装が違う(encoding 指定しなかったり指定したり)ので、他の箇所含め注視していきます。

return EngineManifest(
manifest_version=manifest["manifest_version"],
name=manifest["name"],
Expand Down