Skip to content

Commit

Permalink
追加: engine_manifest.json をバリデーション (#1295)
Browse files Browse the repository at this point in the history
* refactor: `engine_manifest.json` のバリデーションを追加

* fix: lint
  • Loading branch information
tarepan committed May 25, 2024
1 parent fb0d660 commit 2f22130
Showing 1 changed file with 44 additions and 1 deletion.
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()
return EngineManifest(
manifest_version=manifest["manifest_version"],
name=manifest["name"],
Expand Down

0 comments on commit 2f22130

Please sign in to comment.