diff --git a/run.py b/run.py index b73b45b40..f15731def 100644 --- a/run.py +++ b/run.py @@ -35,6 +35,7 @@ AccentPhrase, AudioQuery, DownloadableLibrary, + InstalledLibrary, MorphableTargetInfo, ParseKanaBadRequest, ParseKanaError, @@ -818,7 +819,7 @@ def downloadable_libraries(): @app.get( "/installed_libraries", - response_model=List[DownloadableLibrary], + response_model=Dict[str, InstalledLibrary], tags=["音声ライブラリ管理"], ) def installed_libraries(): diff --git a/voicevox_engine/downloadable_library.py b/voicevox_engine/downloadable_library.py index e4abf88b9..74c255f69 100644 --- a/voicevox_engine/downloadable_library.py +++ b/voicevox_engine/downloadable_library.py @@ -3,11 +3,11 @@ import zipfile from io import BytesIO from pathlib import Path -from typing import List +from typing import Dict from fastapi import HTTPException -from voicevox_engine.model import DownloadableLibrary +from voicevox_engine.model import DownloadableLibrary, InstalledLibrary __all__ = ["LibraryManager"] @@ -59,12 +59,14 @@ def downloadable_libraries(self): ] return list(map(DownloadableLibrary.parse_obj, libraries)) - def installed_libraries(self) -> List[DownloadableLibrary]: - library = [] + def installed_libraries(self) -> Dict[str, InstalledLibrary]: + library = {} for library_dir in self.library_root_dir.iterdir(): if library_dir.is_dir(): with open(library_dir / INFO_FILE, encoding="utf-8") as f: - library.append(json.load(f)) + library[library_dir] = json.load(f) + # アンインストール出来ないライブラリを作る場合、何かしらの条件でFalseを設定する + library[library_dir]["uninstallable"] = True return library def install_library(self, library_id: str, file: BytesIO): diff --git a/voicevox_engine/model.py b/voicevox_engine/model.py index fa5c23e26..9799b2ee6 100644 --- a/voicevox_engine/model.py +++ b/voicevox_engine/model.py @@ -107,7 +107,6 @@ def __init__(self, err: ParseKanaError): class MorphableTargetInfo(BaseModel): - is_morphable: bool = Field(title="指定した話者に対してモーフィングの可否") # FIXME: add reason property # reason: Optional[str] = Field(title="is_morphableがfalseである場合、その理由") @@ -141,6 +140,14 @@ class DownloadableLibrary(BaseModel): speakers: List[LibrarySpeaker] = Field(title="音声ライブラリに含まれる話者のリスト") +class InstalledLibrary(DownloadableLibrary): + """ + インストール済み音声ライブラリの情報 + """ + + uninstallable: bool = Field(title="アンインストール可能かどうか") + + USER_DICT_MIN_PRIORITY = 0 USER_DICT_MAX_PRIORITY = 10