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

整理: CoreManager クラスの新設 #1227

Merged
merged 12 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
fix: corescore_manager へリネーム
tarepan committed May 16, 2024

Verified

This commit was signed with the committer’s verified signature.
slarse Simon Larsén
commit 9306261b422cef69951010120dca0faa5782a85c
6 changes: 3 additions & 3 deletions build_util/make_docs.py
Original file line number Diff line number Diff line change
@@ -36,12 +36,12 @@ def generate_api_docs_html(schema: str) -> str:


if __name__ == "__main__":
cores = CoreManager()
cores.register_core(CoreAdapter(MockCoreWrapper()), "mock")
core_manager = CoreManager()
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "mock")
# FastAPI の機能を用いて OpenAPI schema を生成する
app = generate_app(
tts_engines={"mock": MockTTSEngine()},
cores=cores,
core_manager=core_manager,
latest_core_version="mock",
setting_loader=SettingHandler(USER_SETTING_PATH),
preset_manager=PresetManager( # FIXME: impl MockPresetManager
6 changes: 3 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -257,7 +257,7 @@ def main() -> None:
cpu_num_threads: int | None = args.cpu_num_threads
load_all_models: bool = args.load_all_models

cores = initialize_cores(
core_manager = initialize_cores(
use_gpu=use_gpu,
voicelib_dirs=voicelib_dirs,
voicevox_dir=voicevox_dir,
@@ -266,7 +266,7 @@ def main() -> None:
enable_mock=enable_mock,
load_all_models=load_all_models,
)
tts_engines = make_tts_engines_from_cores(cores)
tts_engines = make_tts_engines_from_cores(core_manager)
assert len(tts_engines) != 0, "音声合成エンジンがありません。"
latest_core_version = get_latest_version(list(tts_engines.keys()))

@@ -326,7 +326,7 @@ def main() -> None:
# ASGI に準拠した VOICEVOX ENGINE アプリケーションを生成する
app = generate_app(
tts_engines,
cores,
core_manager,
latest_core_version,
setting_loader,
preset_manager,
6 changes: 3 additions & 3 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@

@pytest.fixture()
def app_params(tmp_path: Path) -> dict[str, Any]:
cores = initialize_cores(use_gpu=False, enable_mock=True)
tts_engines = make_tts_engines_from_cores(cores)
core_manager = initialize_cores(use_gpu=False, enable_mock=True)
tts_engines = make_tts_engines_from_cores(core_manager)
latest_core_version = get_latest_version(list(tts_engines.keys()))
setting_loader = SettingHandler(Path("./not_exist.yaml"))

@@ -31,7 +31,7 @@ def app_params(tmp_path: Path) -> dict[str, Any]:

return {
"tts_engines": tts_engines,
"cores": cores,
"core_manager": core_manager,
"latest_core_version": latest_core_version,
"setting_loader": setting_loader,
"preset_manager": preset_manager,
68 changes: 34 additions & 34 deletions test/test_core_initializer.py
Original file line number Diff line number Diff line change
@@ -14,22 +14,22 @@
def test_cores_register_core() -> None:
"""CoreManager.register_core() でコアを登録できる。"""
# Inputs
cores = CoreManager()
core_manager = CoreManager()

# Test
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")


def test_cores_versions() -> None:
"""CoreManager.versions() でバージョン一覧を取得できる。"""
# Inputs
cores = CoreManager()
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
core_manager = CoreManager()
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
# Expects
true_versions = ["0.0.1", "0.0.2"]
# Outputs
versions = cores.versions()
versions = core_manager.versions()

# Test
assert true_versions == versions
@@ -38,13 +38,13 @@ def test_cores_versions() -> None:
def test_cores_latest_version() -> None:
"""CoreManager.latest_version() で最新バージョンを取得できる。"""
# Inputs
cores = CoreManager()
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
core_manager = CoreManager()
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
# Expects
true_latest_version = "0.0.2"
# Outputs
latest_version = cores.latest_version()
latest_version = core_manager.latest_version()

# Test
assert true_latest_version == latest_version
@@ -53,15 +53,15 @@ def test_cores_latest_version() -> None:
def test_cores_get_core_specified() -> None:
"""CoreManager.get_core() で登録済みコアをバージョン指定して取得できる。"""
# Inputs
cores = CoreManager()
core_manager = CoreManager()
core1 = CoreAdapter(MockCoreWrapper())
core2 = CoreAdapter(MockCoreWrapper())
cores.register_core(core1, "0.0.1")
cores.register_core(core2, "0.0.2")
core_manager.register_core(core1, "0.0.1")
core_manager.register_core(core2, "0.0.2")
# Expects
true_acquired_core = core2
# Outputs
acquired_core = cores.get_core("0.0.2")
acquired_core = core_manager.get_core("0.0.2")

# Test
assert true_acquired_core == acquired_core
@@ -70,15 +70,15 @@ def test_cores_get_core_specified() -> None:
def test_cores_get_core_latest() -> None:
"""CoreManager.get_core() で最新版コアをバージョン未指定で取得できる。"""
# Inputs
cores = CoreManager()
core_manager = CoreManager()
core1 = CoreAdapter(MockCoreWrapper())
core2 = CoreAdapter(MockCoreWrapper())
cores.register_core(core1, "0.0.1")
cores.register_core(core2, "0.0.2")
core_manager.register_core(core1, "0.0.1")
core_manager.register_core(core2, "0.0.2")
# Expects
true_acquired_core = core2
# Outputs
acquired_core = cores.get_core()
acquired_core = core_manager.get_core()

# Test
assert true_acquired_core == acquired_core
@@ -87,27 +87,27 @@ def test_cores_get_core_latest() -> None:
def test_cores_get_core_missing() -> None:
"""CoreManager.get_core() で存在しないコアを取得しようとするとエラーになる。"""
# Inputs
cores = CoreManager()
core_manager = CoreManager()
core1 = CoreAdapter(MockCoreWrapper())
core2 = CoreAdapter(MockCoreWrapper())
cores.register_core(core1, "0.0.1")
cores.register_core(core2, "0.0.2")
core_manager.register_core(core1, "0.0.1")
core_manager.register_core(core2, "0.0.2")

# Test
with pytest.raises(HTTPException) as _:
cores.get_core("0.0.3")
core_manager.get_core("0.0.3")


def test_cores_has_core_true() -> None:
"""CoreManager.has_core() でコアが登録されていることを確認できる。"""
# Inputs
cores = CoreManager()
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
core_manager = CoreManager()
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
# Expects
true_has = True
# Outputs
has = cores.has_core("0.0.1")
has = core_manager.has_core("0.0.1")

# Test
assert true_has == has
@@ -116,13 +116,13 @@ def test_cores_has_core_true() -> None:
def test_cores_has_core_false() -> None:
"""CoreManager.has_core() でコアが登録されていないことを確認できる。"""
# Inputs
cores = CoreManager()
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
cores.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
core_manager = CoreManager()
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.1")
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "0.0.2")
# Expects
true_has = False
# Outputs
has = cores.has_core("0.0.3")
has = core_manager.has_core("0.0.3")

# Test
assert true_has == has
@@ -131,15 +131,15 @@ def test_cores_has_core_false() -> None:
def test_cores_items() -> None:
"""CoreManager.items() でコアとバージョンのリストを取得できる。"""
# Inputs
cores = CoreManager()
core_manager = CoreManager()
core1 = CoreAdapter(MockCoreWrapper())
core2 = CoreAdapter(MockCoreWrapper())
cores.register_core(core1, "0.0.1")
cores.register_core(core2, "0.0.2")
core_manager.register_core(core1, "0.0.1")
core_manager.register_core(core2, "0.0.2")
# Expects
true_items = [("0.0.1", core1), ("0.0.2", core2)]
# Outputs
items = cores.items()
items = core_manager.items()

# Test
assert true_items == items
10 changes: 5 additions & 5 deletions voicevox_engine/app/application.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@

def generate_app(
tts_engines: dict[str, TTSEngine],
cores: CoreManager,
core_manager: CoreManager,
latest_core_version: str,
setting_loader: SettingHandler,
preset_manager: PresetManager,
@@ -86,18 +86,18 @@ def get_engine(core_version: str | None) -> TTSEngine:

app.include_router(
generate_tts_pipeline_router(
get_engine, cores, preset_manager, cancellable_engine
get_engine, core_manager, preset_manager, cancellable_engine
)
)
app.include_router(generate_morphing_router(get_engine, cores, metas_store))
app.include_router(generate_morphing_router(get_engine, core_manager, metas_store))
app.include_router(generate_preset_router(preset_manager))
app.include_router(generate_speaker_router(cores, metas_store, root_dir))
app.include_router(generate_speaker_router(core_manager, metas_store, root_dir))
if engine_manifest_data.supported_features.manage_library:
app.include_router(
generate_library_router(engine_manifest_data, library_manager)
)
app.include_router(generate_user_dict_router(user_dict))
app.include_router(generate_engine_info_router(cores, engine_manifest_data))
app.include_router(generate_engine_info_router(core_manager, engine_manifest_data))
app.include_router(generate_setting_router(setting_loader, engine_manifest_data))

@app.get("/", response_class=HTMLResponse, tags=["その他"])
6 changes: 3 additions & 3 deletions voicevox_engine/app/routers/engine_info.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@


def generate_engine_info_router(
cores: CoreManager, engine_manifest_data: EngineManifest
core_manager: CoreManager, engine_manifest_data: EngineManifest
) -> APIRouter:
"""エンジン情報 API Router を生成する"""
router = APIRouter()
@@ -25,7 +25,7 @@ async def version() -> str:
async def core_versions() -> Response:
"""利用可能なコアのバージョン一覧を取得します。"""
return Response(
content=json.dumps(cores.versions()),
content=json.dumps(core_manager.versions()),
media_type="application/json",
)

@@ -34,7 +34,7 @@ async def core_versions() -> Response:
)
def supported_devices(core_version: str | None = None) -> Response:
"""対応デバイスの一覧を取得します。"""
supported_devices = cores.get_core(core_version).supported_devices
supported_devices = core_manager.get_core(core_version).supported_devices
if supported_devices is None:
raise HTTPException(status_code=422, detail="非対応の機能です。")
return Response(
6 changes: 3 additions & 3 deletions voicevox_engine/app/routers/morphing.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@

def generate_morphing_router(
get_engine: Callable[[str | None], TTSEngine],
cores: CoreManager,
core_manager: CoreManager,
metas_store: MetasStore,
) -> APIRouter:
"""モーフィング API Router を生成する"""
@@ -52,7 +52,7 @@ def morphable_targets(
プロパティが存在しない場合は、モーフィングが許可されているとみなします。
返り値のスタイルIDはstring型なので注意。
"""
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)

try:
speakers = metas_store.load_combined_metas(core=core)
@@ -95,7 +95,7 @@ def _synthesis_morphing(
モーフィングの割合は`morph_rate`で指定でき、0.0でベースのスタイル、1.0でターゲットのスタイルに近づきます。
"""
engine = get_engine(core_version)
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)

try:
speakers = metas_store.load_combined_metas(core=core)
12 changes: 6 additions & 6 deletions voicevox_engine/app/routers/speaker.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def b64encode_str(s: bytes) -> str:


def generate_speaker_router(
cores: CoreManager,
core_manager: CoreManager,
metas_store: MetasStore,
root_dir: Path,
) -> APIRouter:
@@ -30,7 +30,7 @@ def generate_speaker_router(
def speakers(
core_version: str | None = None,
) -> list[Speaker]:
speakers = metas_store.load_combined_metas(cores.get_core(core_version))
speakers = metas_store.load_combined_metas(core_manager.get_core(core_version))
return filter_speakers_and_styles(speakers, "speaker")

@router.get("/speaker_info", tags=["その他"])
@@ -79,7 +79,7 @@ def _speaker_info(

# 該当話者の検索
speakers = parse_obj_as(
list[Speaker], json.loads(cores.get_core(core_version).speakers)
list[Speaker], json.loads(core_manager.get_core(core_version).speakers)
)
speakers = filter_speakers_and_styles(speakers, speaker_or_singer)
for i in range(len(speakers)):
@@ -147,7 +147,7 @@ def _speaker_info(
def singers(
core_version: str | None = None,
) -> list[Speaker]:
singers = metas_store.load_combined_metas(cores.get_core(core_version))
singers = metas_store.load_combined_metas(core_manager.get_core(core_version))
return filter_speakers_and_styles(singers, "singer")

@router.get("/singer_info", tags=["その他"])
@@ -180,7 +180,7 @@ def initialize_speaker(
指定されたスタイルを初期化します。
実行しなくても他のAPIは使用できますが、初回実行時に時間がかかることがあります。
"""
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)
core.initialize_style_id_synthesis(style_id, skip_reinit=skip_reinit)
return Response(status_code=204)

@@ -192,7 +192,7 @@ def is_initialized_speaker(
"""
指定されたスタイルが初期化されているかどうかを返します。
"""
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)
return core.is_initialized_style_id_synthesis(style_id)

return router
8 changes: 4 additions & 4 deletions voicevox_engine/app/routers/tts_pipeline.py
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@

def generate_tts_pipeline_router(
get_engine: Callable[[str | None], TTSEngine],
cores: CoreManager,
core_manager: CoreManager,
preset_manager: PresetManager,
cancellable_engine: CancellableEngine | None,
) -> APIRouter:
@@ -54,7 +54,7 @@ def audio_query(
音声合成用のクエリの初期値を得ます。ここで得られたクエリはそのまま音声合成に利用できます。各値の意味は`Schemas`を参照してください。
"""
engine = get_engine(core_version)
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)
accent_phrases = engine.create_accent_phrases(text, style_id)
return AudioQuery(
accent_phrases=accent_phrases,
@@ -83,7 +83,7 @@ def audio_query_from_preset(
音声合成用のクエリの初期値を得ます。ここで得られたクエリはそのまま音声合成に利用できます。各値の意味は`Schemas`を参照してください。
"""
engine = get_engine(core_version)
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)
try:
presets = preset_manager.load_presets()
except PresetInputError as err:
@@ -328,7 +328,7 @@ def sing_frame_audio_query(
歌唱音声合成用のクエリの初期値を得ます。ここで得られたクエリはそのまま歌唱音声合成に利用できます。各値の意味は`Schemas`を参照してください。
"""
engine = get_engine(core_version)
core = cores.get_core(core_version)
core = core_manager.get_core(core_version)
phonemes, f0, volume = engine.create_sing_phoneme_and_f0_and_volume(
score, style_id
)
Loading