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

整理: ライブラリ関連の Model を移動 #1328

Merged
merged 3 commits into from
Jun 2, 2024
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
2 changes: 1 addition & 1 deletion test/test_library_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from fastapi import HTTPException

from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.library.library_manager import LibraryManager

vvlib_manifest_name = "vvlib_manifest.json"

Expand Down
2 changes: 1 addition & 1 deletion voicevox_engine/app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from voicevox_engine.cancellable_engine import CancellableEngine
from voicevox_engine.core.core_initializer import CoreManager
from voicevox_engine.engine_manifest import EngineManifest
from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.library.library_manager import LibraryManager
from voicevox_engine.metas.MetasStore import MetasStore
from voicevox_engine.preset.Preset import PresetManager
from voicevox_engine.setting.Setting import CorsPolicyMode, SettingHandler
Expand Down
2 changes: 1 addition & 1 deletion voicevox_engine/app/openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi

from voicevox_engine.model import BaseLibraryInfo, VvlibManifest
from voicevox_engine.library.model import BaseLibraryInfo, VvlibManifest


def configure_openapi_schema(app: FastAPI) -> FastAPI:
Expand Down
4 changes: 2 additions & 2 deletions voicevox_engine/app/routers/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from fastapi import APIRouter, Depends, HTTPException, Path, Request

from voicevox_engine.engine_manifest import EngineManifest
from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.model import DownloadableLibraryInfo, InstalledLibraryInfo
from voicevox_engine.library.library_manager import LibraryManager
from voicevox_engine.library.model import DownloadableLibraryInfo, InstalledLibraryInfo

from ..dependencies import check_disabled_mutable_api

Expand Down
3 changes: 1 addition & 2 deletions voicevox_engine/app/routers/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from pydantic import parse_obj_as

from voicevox_engine.core.core_initializer import CoreManager
from voicevox_engine.metas.Metas import StyleId
from voicevox_engine.metas.Metas import Speaker, SpeakerInfo, StyleId
from voicevox_engine.metas.MetasStore import MetasStore, filter_speakers_and_styles
from voicevox_engine.model import Speaker, SpeakerInfo


def b64encode_str(s: bytes) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import ValidationError
from semver.version import Version

from voicevox_engine.model import (
from voicevox_engine.library.model import (
DownloadableLibraryInfo,
InstalledLibraryInfo,
VvlibManifest,
Expand Down
62 changes: 62 additions & 0 deletions voicevox_engine/library/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
ライブラリ機能に関して API と ENGINE 内部実装が共有するモデル

「API と ENGINE 内部実装が共有するモデル」については `voicevox_engine/model.py` の module docstring を確認すること。
tarepan marked this conversation as resolved.
Show resolved Hide resolved
"""

from pydantic import BaseModel, Field, StrictStr

from voicevox_engine.metas.Metas import Speaker, SpeakerInfo


class LibrarySpeaker(BaseModel):
"""
音声ライブラリに含まれる話者の情報
"""

speaker: Speaker = Field(title="話者情報")
speaker_info: SpeakerInfo = Field(title="話者の追加情報")


class BaseLibraryInfo(BaseModel):
"""
音声ライブラリの情報
"""

name: str = Field(title="音声ライブラリの名前")
uuid: str = Field(title="音声ライブラリのUUID")
version: str = Field(title="音声ライブラリのバージョン")
download_url: str = Field(title="音声ライブラリのダウンロードURL")
bytes: int = Field(title="音声ライブラリのバイト数")
speakers: list[LibrarySpeaker] = Field(title="音声ライブラリに含まれる話者のリスト")


# 今後InstalledLibraryInfo同様に拡張する可能性を考え、モデルを分けている
class DownloadableLibraryInfo(BaseLibraryInfo):
"""
ダウンロード可能な音声ライブラリの情報
"""

pass


class InstalledLibraryInfo(BaseLibraryInfo):
"""
インストール済み音声ライブラリの情報
"""

uninstallable: bool = Field(title="アンインストール可能かどうか")


class VvlibManifest(BaseModel):
"""
vvlib(VOICEVOX Library)に関する情報
"""

manifest_version: StrictStr = Field(title="マニフェストバージョン")
name: StrictStr = Field(title="音声ライブラリ名")
version: StrictStr = Field(title="音声ライブラリバージョン")
uuid: StrictStr = Field(title="音声ライブラリのUUID")
brand_name: StrictStr = Field(title="エンジンのブランド名")
engine_name: StrictStr = Field(title="エンジン名")
engine_uuid: StrictStr = Field(title="エンジンのUUID")
57 changes: 1 addition & 56 deletions voicevox_engine/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from re import findall, fullmatch
from typing import Any

from pydantic import BaseModel, Field, StrictStr, validator

from .metas.Metas import Speaker, SpeakerInfo
from pydantic import BaseModel, Field, validator


class Mora(BaseModel):
Expand Down Expand Up @@ -165,45 +163,6 @@ def __init__(self, style_id: int, *args: object, **kywrds: object) -> None:
super().__init__(f"style_id {style_id} is not found.", *args, **kywrds)


class LibrarySpeaker(BaseModel):
"""
音声ライブラリに含まれる話者の情報
"""

speaker: Speaker = Field(title="話者情報")
speaker_info: SpeakerInfo = Field(title="話者の追加情報")


class BaseLibraryInfo(BaseModel):
"""
音声ライブラリの情報
"""

name: str = Field(title="音声ライブラリの名前")
uuid: str = Field(title="音声ライブラリのUUID")
version: str = Field(title="音声ライブラリのバージョン")
download_url: str = Field(title="音声ライブラリのダウンロードURL")
bytes: int = Field(title="音声ライブラリのバイト数")
speakers: list[LibrarySpeaker] = Field(title="音声ライブラリに含まれる話者のリスト")


# 今後InstalledLibraryInfo同様に拡張する可能性を考え、モデルを分けている
class DownloadableLibraryInfo(BaseLibraryInfo):
"""
ダウンロード可能な音声ライブラリの情報
"""

pass


class InstalledLibraryInfo(BaseLibraryInfo):
"""
インストール済み音声ライブラリの情報
"""

uninstallable: bool = Field(title="アンインストール可能かどうか")


USER_DICT_MIN_PRIORITY = 0
USER_DICT_MAX_PRIORITY = 10

Expand Down Expand Up @@ -343,17 +302,3 @@ class SupportedFeaturesInfo(BaseModel):
title="疑似疑問文に対応しているかどうか"
)
support_switching_device: bool = Field(title="CPU/GPUの切り替えが可能かどうか")


class VvlibManifest(BaseModel):
"""
vvlib(VOICEVOX Library)に関する情報
"""

manifest_version: StrictStr = Field(title="マニフェストバージョン")
name: StrictStr = Field(title="音声ライブラリ名")
version: StrictStr = Field(title="音声ライブラリバージョン")
uuid: StrictStr = Field(title="音声ライブラリのUUID")
brand_name: StrictStr = Field(title="エンジンのブランド名")
engine_name: StrictStr = Field(title="エンジン名")
engine_uuid: StrictStr = Field(title="エンジンのUUID")