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

追加: デフォルトプリセット機能を削除しプリセット保存先を指定する機能へ変更 #1323

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ COPY --from=download-onnxruntime-env /opt/onnxruntime /opt/onnxruntime
# Add local files
ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine
ADD ./docs /opt/voicevox_engine/docs
ADD ./run.py ./presets.yaml ./engine_manifest.json /opt/voicevox_engine/
ADD ./run.py ./engine_manifest.json /opt/voicevox_engine/
ADD ./resources /opt/voicevox_engine/resources
ADD ./build_util/generate_licenses.py /opt/voicevox_engine/build_util/
ADD ./build_util/licenses /opt/voicevox_engine/build_util/licenses
Expand Down
5 changes: 2 additions & 3 deletions build_util/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ def generate_api_docs_html(schema: str) -> str:
core_manager.register_core(CoreAdapter(MockCoreWrapper()), "mock")
tts_engines = TTSEngineManager()
tts_engines.register_engine(MockTTSEngine(), "mock")
preset_path = engine_root() / "presets.yaml"
# FastAPI の機能を用いて OpenAPI schema を生成する
app = generate_app(
tts_engines=tts_engines,
core_manager=core_manager,
latest_core_version="mock",
setting_loader=SettingHandler(USER_SETTING_PATH),
preset_manager=PresetManager( # FIXME: impl MockPresetManager
preset_path=engine_root() / "presets.yaml",
),
preset_manager=PresetManager(preset_path),
user_dict=UserDictionary(),
engine_manifest=load_manifest(engine_manifest_path()),
)
Expand Down
10 changes: 0 additions & 10 deletions presets.yaml

This file was deleted.

1 change: 0 additions & 1 deletion run.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ datas = [
('speaker_info', 'speaker_info'),
('engine_manifest.json', '.'),
('licenses.json', '.'),
('presets.yaml', '.'),
]
datas += collect_data_files('pyopenjtalk')

Expand Down
26 changes: 24 additions & 2 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any

import pytest
import yaml
from fastapi import FastAPI
from fastapi.testclient import TestClient

Expand Down Expand Up @@ -32,8 +33,9 @@ def app_params(tmp_path: Path) -> dict[str, Any]:
setting_loader = SettingHandler(Path("./not_exist.yaml"))

# テスト用に隔離されたプリセットを生成する
preset_path = Path("./presets.yaml")
preset_manager = PresetManager(_copy_under_dir(preset_path, tmp_path))
preset_path = tmp_path / "presets.yaml"
_generate_preset(preset_path)
preset_manager = PresetManager(preset_path)

# テスト用に隔離されたユーザー辞書を生成する
user_dict = UserDictionary(
Expand Down Expand Up @@ -65,6 +67,26 @@ def client(app: FastAPI) -> TestClient:
return TestClient(app)


def _generate_preset(preset_path: Path) -> None:
"""指定パス下にプリセットファイルを生成する。"""
contents = [
{
"id": 1,
"name": "サンプルプリセット",
"speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
"style_id": 0,
"speedScale": 1,
"pitchScale": 0,
"intonationScale": 1,
"volumeScale": 1,
"prePhonemeLength": 0.1,
"postPhonemeLength": 0.1,
}
]
with open(preset_path, mode="w", encoding="utf-8") as f:
yaml.safe_dump(contents, f, allow_unicode=True, sort_keys=False)


def _generate_user_dict(dir_path: Path) -> Path:
"""指定されたディレクトリ下にユーザー辞書ファイルを生成し、生成されたファイルのパスを返す。"""
contents = {
Expand Down
20 changes: 20 additions & 0 deletions voicevox_engine/preset/Preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel, Field, ValidationError, parse_obj_as

from voicevox_engine.metas.Metas import StyleId
from voicevox_engine.utility.path_utility import engine_root


class Preset(BaseModel):
Expand Down Expand Up @@ -51,6 +52,25 @@ def __init__(self, preset_path: Path):
self.last_modified_time = 0.0
self.preset_path = preset_path

# プリセットファイルが無指定の場合、初期値を生成する
default_path = engine_root() / "presets.yaml"
preset_not_specified = default_path.resolve() == preset_path.resolve()
if not self.preset_path.exists() and preset_not_specified:
self.preset_path.write_text("[]")
default_preset = Preset(
id=1,
name="サンプルプリセット",
speaker_uuid="7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
style_id=0,
speedScale=1,
pitchScale=0,
intonationScale=1,
volumeScale=1,
prePhonemeLength=0.1,
postPhonemeLength=0.1,
)
self.add_preset(default_preset)

def _refresh_cache(self) -> None:
"""プリセットの設定ファイルの最新状態をキャッシュへ反映する"""

Expand Down