Skip to content

Commit

Permalink
MAINT: FastAPIのパラメータを全てAnnotatedに移行する (#1183)
Browse files Browse the repository at this point in the history
maint: FastAPIのパラメータを全て`Annotated`に移行する
  • Loading branch information
sabonerune authored Apr 26, 2024
1 parent c16554d commit 3a81ba8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
20 changes: 11 additions & 9 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ def morphable_targets(
)
def _synthesis_morphing(
query: AudioQuery,
base_style_id: StyleId = Query(alias="base_speaker"), # noqa: B008
target_style_id: StyleId = Query(alias="target_speaker"), # noqa: B008
morph_rate: float = Query(..., ge=0.0, le=1.0), # noqa: B008
base_style_id: Annotated[StyleId, Query(alias="base_speaker")],
target_style_id: Annotated[StyleId, Query(alias="target_speaker")],
morph_rate: Annotated[float, Query(ge=0.0, le=1.0)],
core_version: str | None = None,
) -> FileResponse:
"""
Expand Down Expand Up @@ -450,11 +450,13 @@ def uninstall_library(

@app.post("/initialize_speaker", status_code=204, tags=["その他"])
def initialize_speaker(
style_id: StyleId = Query(alias="speaker"), # noqa: B008
skip_reinit: bool = Query( # noqa: B008
default=False,
description="既に初期化済みのスタイルの再初期化をスキップするかどうか",
),
style_id: Annotated[StyleId, Query(alias="speaker")],
skip_reinit: Annotated[
bool,
Query(
description="既に初期化済みのスタイルの再初期化をスキップするかどうか",
),
] = False,
core_version: str | None = None,
) -> Response:
"""
Expand All @@ -467,7 +469,7 @@ def initialize_speaker(

@app.get("/is_initialized_speaker", response_model=bool, tags=["その他"])
def is_initialized_speaker(
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> bool:
"""
Expand Down
6 changes: 4 additions & 2 deletions voicevox_engine/app/routers/setting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""設定機能を提供する API Router"""

from typing import Annotated

from fastapi import APIRouter, Depends, Form, Request, Response
from fastapi.templating import Jinja2Templates

Expand Down Expand Up @@ -49,8 +51,8 @@ def setting_get(request: Request) -> Response:
dependencies=[Depends(check_disabled_mutable_api)],
)
def setting_post(
cors_policy_mode: CorsPolicyMode = Form(), # noqa
allow_origin: str | None = Form(default=None), # noqa
cors_policy_mode: Annotated[CorsPolicyMode, Form()],
allow_origin: Annotated[str | None, Form()] = None,
) -> Response:
"""
設定を更新します。
Expand Down
30 changes: 16 additions & 14 deletions voicevox_engine/app/routers/tts_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate_router(
)
def audio_query(
text: str,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> AudioQuery:
"""
Expand Down Expand Up @@ -127,7 +127,7 @@ def audio_query_from_preset(
)
def accent_phrases(
text: str,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
is_kana: bool = False,
core_version: str | None = None,
) -> list[AccentPhrase]:
Expand Down Expand Up @@ -159,7 +159,7 @@ def accent_phrases(
)
def mora_data(
accent_phrases: list[AccentPhrase],
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> list[AccentPhrase]:
engine = get_engine(core_version)
Expand All @@ -173,7 +173,7 @@ def mora_data(
)
def mora_length(
accent_phrases: list[AccentPhrase],
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> list[AccentPhrase]:
engine = get_engine(core_version)
Expand All @@ -187,7 +187,7 @@ def mora_length(
)
def mora_pitch(
accent_phrases: list[AccentPhrase],
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> list[AccentPhrase]:
engine = get_engine(core_version)
Expand All @@ -208,11 +208,13 @@ def mora_pitch(
)
def synthesis(
query: AudioQuery,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
enable_interrogative_upspeak: bool = Query( # noqa: B008
default=True,
description="疑問系のテキストが与えられたら語尾を自動調整する",
),
style_id: Annotated[StyleId, Query(alias="speaker")],
enable_interrogative_upspeak: Annotated[
bool,
Query(
description="疑問系のテキストが与えられたら語尾を自動調整する",
),
] = True,
core_version: str | None = None,
) -> FileResponse:
engine = get_engine(core_version)
Expand Down Expand Up @@ -247,7 +249,7 @@ def synthesis(
def cancellable_synthesis(
query: AudioQuery,
request: Request,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> FileResponse:
if cancellable_engine is None:
Expand Down Expand Up @@ -284,7 +286,7 @@ def cancellable_synthesis(
)
def multi_synthesis(
queries: list[AudioQuery],
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> FileResponse:
engine = get_engine(core_version)
Expand Down Expand Up @@ -324,7 +326,7 @@ def multi_synthesis(
)
def sing_frame_audio_query(
score: Score,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> FrameAudioQuery:
"""
Expand Down Expand Up @@ -359,7 +361,7 @@ def sing_frame_audio_query(
)
def frame_synthesis(
query: FrameAudioQuery,
style_id: StyleId = Query(alias="speaker"), # noqa: B008
style_id: Annotated[StyleId, Query(alias="speaker")],
core_version: str | None = None,
) -> FileResponse:
"""
Expand Down

0 comments on commit 3a81ba8

Please sign in to comment.