diff --git a/voicevox_engine/engine_manifest.py b/voicevox_engine/engine_manifest.py index 0ea321be3..9307416e5 100644 --- a/voicevox_engine/engine_manifest.py +++ b/voicevox_engine/engine_manifest.py @@ -7,14 +7,16 @@ import json from base64 import b64encode +from dataclasses import asdict, dataclass from pathlib import Path from typing import TypeAlias -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, TypeAdapter from pydantic.json_schema import SkipJsonSchema -class FeatureSupportJson(BaseModel): +@dataclass(frozen=True) +class FeatureSupportJson: """`engine_manifest.json` の機能サポート状況""" type: str @@ -22,7 +24,8 @@ class FeatureSupportJson(BaseModel): name: str -class SupportedFeaturesJson(BaseModel): +@dataclass(frozen=True) +class SupportedFeaturesJson: """`engine_manifest.json` のサポート機能一覧""" adjust_mora_pitch: FeatureSupportJson @@ -37,7 +40,8 @@ class SupportedFeaturesJson(BaseModel): manage_library: FeatureSupportJson -class EngineManifestJson(BaseModel): +@dataclass(frozen=True) +class EngineManifestJson: """`engine_manifest.json` のコンテンツ""" manifest_version: str @@ -57,6 +61,9 @@ class EngineManifestJson(BaseModel): supported_features: SupportedFeaturesJson +_manifest_json_adapter = TypeAdapter(EngineManifestJson) + + class UpdateInfo(BaseModel): """ エンジンのアップデート情報 @@ -135,7 +142,7 @@ def load_manifest(manifest_path: Path) -> EngineManifest: """エンジンマニフェストを指定ファイルから読み込む。""" root_dir = manifest_path.parent - manifest = EngineManifestJson.model_validate_json(manifest_path.read_bytes()) + manifest = _manifest_json_adapter.validate_json(manifest_path.read_bytes()) return EngineManifest( manifest_version=manifest.manifest_version, name=manifest.name, @@ -161,6 +168,6 @@ def load_manifest(manifest_path: Path) -> EngineManifest: ], supported_features={ key: item["value"] - for key, item in manifest.supported_features.model_dump().items() + for key, item in asdict(manifest.supported_features).items() }, )