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

installed_library APIの改善 #691

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
AccentPhrase,
AudioQuery,
DownloadableLibrary,
InstalledLibrary,
MorphableTargetInfo,
ParseKanaBadRequest,
ParseKanaError,
Expand Down Expand Up @@ -818,7 +819,7 @@ def downloadable_libraries():

@app.get(
"/installed_libraries",
response_model=List[DownloadableLibrary],
response_model=Dict[str, InstalledLibrary],
tags=["音声ライブラリ管理"],
)
def installed_libraries():
Expand Down
12 changes: 7 additions & 5 deletions voicevox_engine/downloadable_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion voicevox_engine/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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である場合、その理由")
Expand Down Expand Up @@ -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

Expand Down