diff --git a/requirements-dev.txt b/requirements-dev.txt index 2c877c547..9b274bec2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -28,6 +28,7 @@ jeepney==0.8.0 ; python_version >= "3.11" and python_version < "3.12" and sys_pl jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12" jsonschema==4.17.3 ; python_version >= "3.11" and python_version < "3.12" keyring==24.2.0 ; python_version >= "3.11" and python_version < "3.12" +ko2kana==1.8 ; python_version >= "3.11" and python_version < "3.12" macholib==1.16.2 ; python_version >= "3.11" and python_version < "3.12" and sys_platform == "darwin" markupsafe==2.1.3 ; python_version >= "3.11" and python_version < "3.12" more-itertools==10.1.0 ; python_version >= "3.11" and python_version < "3.12" diff --git a/requirements-test.txt b/requirements-test.txt index ea3290c26..e3802c18d 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -39,6 +39,7 @@ jeepney==0.8.0 ; python_version >= "3.11" and python_version < "3.12" and sys_pl jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12" jsonschema==4.17.3 ; python_version >= "3.11" and python_version < "3.12" keyring==24.2.0 ; python_version >= "3.11" and python_version < "3.12" +ko2kana==1.8 ; python_version >= "3.11" and python_version < "3.12" markupsafe==2.1.3 ; python_version >= "3.11" and python_version < "3.12" mccabe==0.7.0 ; python_version >= "3.11" and python_version < "3.12" more-itertools==10.1.0 ; python_version >= "3.11" and python_version < "3.12" diff --git a/requirements.txt b/requirements.txt index aa124e9c6..ed40a3faa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ fastapi==0.103.2 ; python_version >= "3.11" and python_version < "3.12" h11==0.14.0 ; python_version >= "3.11" and python_version < "3.12" idna==3.4 ; python_version >= "3.11" and python_version < "3.12" jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12" +ko2kana==1.8 ; python_version >= "3.11" and python_version < "3.12" markupsafe==2.1.3 ; python_version >= "3.11" and python_version < "3.12" numpy==1.26.2 ; python_version >= "3.11" and python_version < "3.12" platformdirs==3.10.0 ; python_version >= "3.11" and python_version < "3.12" diff --git a/run.py b/run.py index 34671965a..ec2917b8c 100644 --- a/run.py +++ b/run.py @@ -22,8 +22,8 @@ from fastapi.openapi.utils import get_openapi from fastapi.responses import JSONResponse from fastapi.templating import Jinja2Templates +from ko2kana import toKana from pydantic import ValidationError, parse_obj_as -from starlette.background import BackgroundTask from starlette.middleware.errors import ServerErrorMiddleware from starlette.responses import FileResponse @@ -137,6 +137,7 @@ def generate_app( latest_core_version: str, setting_loader: SettingHandler, preset_manager: PresetManager, + experimental_katakana_transcription: bool, cancellable_engine: CancellableEngine | None = None, root_dir: Optional[Path] = None, cors_policy_mode: CorsPolicyMode = CorsPolicyMode.localapps, @@ -280,6 +281,8 @@ def audio_query( """ engine = get_engine(core_version) core = get_core(core_version) + if experimental_katakana_transcription: + text = toKana(text).replace(" ", "") accent_phrases = engine.create_accent_phrases(text, style_id) return AudioQuery( accent_phrases=accent_phrases, @@ -321,6 +324,8 @@ def audio_query_from_preset( else: raise HTTPException(status_code=422, detail="該当するプリセットIDが見つかりません") + if experimental_katakana_transcription: + text = toKana(text).replace(" ", "") accent_phrases = engine.create_accent_phrases(text, selected_preset.style_id) return AudioQuery( accent_phrases=accent_phrases, @@ -371,6 +376,8 @@ def accent_phrases( status_code=400, detail=ParseKanaBadRequest(err).dict() ) else: + if experimental_katakana_transcription: + text = toKana(text).replace(" ", "") return engine.create_accent_phrases(text, style_id) @app.post( @@ -1495,6 +1502,12 @@ def main() -> None: ), ) + parser.add_argument( + "--experimental_katakana_transcription", + action="store_true", + help="韓国語と英語の発音をカタカナに置き換えます。数字は変換しません。", + ) + parser.add_argument( "--disable_mutable_api", action="store_true", @@ -1595,6 +1608,7 @@ def main() -> None: latest_core_version, setting_loader, preset_manager=preset_manager, + experimental_katakana_transcription=args.experimental_katakana_transcription, cancellable_engine=cancellable_engine, root_dir=root_dir, cors_policy_mode=cors_policy_mode,