Skip to content

Commit

Permalink
installed_library APIの改善 (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-chan authored Jun 10, 2023
1 parent 4b0e1b1 commit 4b296fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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

0 comments on commit 4b296fd

Please sign in to comment.