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

experimental_katakana_transcription オプションの追加 #834

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
Loading