Skip to content

Commit

Permalink
add is_morphable api
Browse files Browse the repository at this point in the history
  • Loading branch information
Segu-g committed Jan 18, 2023
1 parent 8bf3443 commit efdec12
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
27 changes: 27 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,33 @@ def multi_synthesis(
background=BackgroundTask(delete_file, f.name),
)

@app.get(
"/is_morphable",
response_class=bool,
tag=["音声合成"],
summary="2人の話者でモーフィングが可能かどうか返す",
)
def is_morphable(
base_speaker: int,
target_speaker: int,
core_version: Optional[str] = None,
):
"""
指定された2人の話者でモーフィング機能を利用可能か返します。
モーフィングの許可/禁止は`/speakers`の`speaker.supportedFeatures.synthesisMorphing`に記載されています。
プロパティが存在しない場合は、モーフィングが許可されているとみなします。
"""
engine = get_engine(core_version)

is_permitted = is_synthesis_morphing_permitted(
engine, base_speaker, target_speaker
)

if is_permitted is None:
raise HTTPException(status_code=404, detail="該当する話者が見つかりません")

return is_permitted

@app.post(
"/synthesis_morphing",
response_class=FileResponse,
Expand Down
13 changes: 5 additions & 8 deletions voicevox_engine/morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from voicevox_engine.synthesis_engine.synthesis_engine_base import SynthesisEngineBase

from .model import SpeakerSupportSynthesisMorphing, AudioQuery
from .model import AudioQuery, SpeakerSupportSynthesisMorphing
from .synthesis_engine import SynthesisEngine


Expand Down Expand Up @@ -67,11 +67,9 @@ def is_synthesis_morphing_permitted(
if base_speaker_info is None or target_speaker_info is None:
return None

base_speaker_morphing_info: SpeakerSupportSynthesisMorphing = (
base_speaker_info.get("supported_features", dict()).get(
"synthesis_morphing", SpeakerSupportSynthesisMorphing(None)
)
)
base_speaker_morphing_info: SpeakerSupportSynthesisMorphing = base_speaker_info.get(
"supported_features", dict()
).get("synthesis_morphing", SpeakerSupportSynthesisMorphing(None))

target_speaker_morphing_info: SpeakerSupportSynthesisMorphing = (
target_speaker_info.get("supported_features", dict()).get(
Expand All @@ -85,8 +83,7 @@ def is_synthesis_morphing_permitted(
):
return False
if (
base_speaker_morphing_info
== SpeakerSupportSynthesisMorphing.SELF_MORPHING_ONLY
base_speaker_morphing_info == SpeakerSupportSynthesisMorphing.SELF_MORPHING_ONLY
or target_speaker_morphing_info
== SpeakerSupportSynthesisMorphing.SELF_MORPHING_ONLY
):
Expand Down

0 comments on commit efdec12

Please sign in to comment.