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

Python APIにNewTypeを導入 #678

Merged
merged 1 commit into from
Nov 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
AudioQuery,
Mora,
SpeakerMeta,
StyleId,
StyleVersion,
SupportedDevices,
UserDictWord,
UserDictWordType,
VoiceModelId,
)
from ._rust import ( # noqa: F401
ExtractFullContextLabelError,
Expand Down Expand Up @@ -61,7 +64,9 @@
"SaveUserDictError",
"SpeakerMeta",
"StyleAlreadyLoadedError",
"StyleId",
"StyleNotFoundError",
"StyleVersion",
"SupportedDevices",
"Synthesizer",
"VoiceModel",
Expand All @@ -70,5 +75,6 @@
"UserDict",
"UserDictWord",
"UserDictWordType",
"VoiceModelId",
"WordNotFoundError",
]
33 changes: 30 additions & 3 deletions crates/voicevox_core_python_api/python/voicevox_core/_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
import dataclasses
from enum import Enum
from typing import List, Optional
from typing import List, NewType, Optional

import pydantic

from ._rust import _to_zenkaku, _validate_pronunciation

StyleId = NewType("StyleId", int)
"""
スタイルID。

Parameters
----------
x : int
"""

StyleVersion = NewType("StyleVersion", str)
"""
スタイルのバージョン。

Parameters
----------
x : str
"""

VoiceModelId = NewType("VoiceModelId", str)
"""
音声モデルID。

Parameters
----------
x : str
"""


@pydantic.dataclasses.dataclass
class StyleMeta:
Expand All @@ -14,7 +41,7 @@ class StyleMeta:
name: str
"""スタイル名。"""

id: int
id: StyleId
"""スタイルID。"""


Expand All @@ -31,7 +58,7 @@ class SpeakerMeta:
speaker_uuid: str
"""話者のバージョン。"""

version: str
version: StyleVersion
"""話者のUUID。"""


Expand Down
28 changes: 15 additions & 13 deletions crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ if TYPE_CHECKING:
AccentPhrase,
AudioQuery,
SpeakerMeta,
StyleId,
SupportedDevices,
UserDict,
UserDictWord,
VoiceModelId,
)

__version__: str
Expand Down Expand Up @@ -43,7 +45,7 @@ class VoiceModel:
"""
...
@property
def id(self) -> str:
def id(self) -> VoiceModelId:
"""ID。"""
...
@property
Expand Down Expand Up @@ -118,7 +120,7 @@ class Synthesizer:
読み込むモデルのスタイルID。
"""
...
def unload_voice_model(self, voice_model_id: str) -> None:
def unload_voice_model(self, voice_model_id: Union[VoiceModelId, str]) -> None:
"""
音声モデルの読み込みを解除する。

Expand All @@ -128,7 +130,7 @@ class Synthesizer:
音声モデルID。
"""
...
def is_loaded_voice_model(self, voice_model_id: str) -> bool:
def is_loaded_voice_model(self, voice_model_id: Union[VoiceModelId, str]) -> bool:
"""
指定したvoice_model_idのモデルが読み込まれているか判定する。

Expand All @@ -145,7 +147,7 @@ class Synthesizer:
async def audio_query_from_kana(
self,
kana: str,
style_id: int,
style_id: Union[StyleId, int],
) -> AudioQuery:
"""
AquesTalk風記法から :class:`AudioQuery` を生成する。
Expand All @@ -165,7 +167,7 @@ class Synthesizer:
async def audio_query(
self,
text: str,
style_id: int,
style_id: Union[StyleId, int],
) -> AudioQuery:
"""
日本語のテキストから :class:`AudioQuery` を生成する。
Expand All @@ -185,7 +187,7 @@ class Synthesizer:
async def create_accent_phrases_from_kana(
self,
kana: str,
style_id: int,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
"""
AquesTalk風記法からAccentPhrase(アクセント句)の配列を生成する。
Expand All @@ -205,7 +207,7 @@ class Synthesizer:
async def create_accent_phrases(
self,
text: str,
style_id: int,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
"""
日本語のテキストからAccentPhrase(アクセント句)の配列を生成する。
Expand All @@ -225,7 +227,7 @@ class Synthesizer:
async def replace_mora_data(
self,
accent_phrases: List[AccentPhrase],
style_id: int,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
"""
アクセント句の音高・音素長を変更した新しいアクセント句の配列を生成する。
Expand All @@ -247,7 +249,7 @@ class Synthesizer:
async def replace_phoneme_length(
self,
accent_phrases: List[AccentPhrase],
style_id: int,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
"""
アクセント句の音素長を変更した新しいアクセント句の配列を生成する。
Expand All @@ -265,7 +267,7 @@ class Synthesizer:
async def replace_mora_pitch(
self,
accent_phrases: List[AccentPhrase],
style_id: int,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
"""
アクセント句の音高を変更した新しいアクセント句の配列を生成する。
Expand All @@ -283,7 +285,7 @@ class Synthesizer:
async def synthesis(
self,
audio_query: AudioQuery,
style_id: int,
style_id: Union[StyleId, int],
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand All @@ -306,7 +308,7 @@ class Synthesizer:
async def tts_from_kana(
self,
kana: str,
style_id: int,
style_id: Union[StyleId, int],
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand All @@ -325,7 +327,7 @@ class Synthesizer:
async def tts(
self,
text: str,
style_id: int,
style_id: Union[StyleId, int],
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand Down
Loading