Skip to content

Commit

Permalink
Merge branch 'main' into feat-download-vvms-from-voicevox-vvm
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 20, 2025
2 parents eedbc72 + b20f8b6 commit 20c6c43
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 88 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: Swatinem/rust-cache@v2
with:
key: "cargo-unit-test-cache"
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_python_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ easy-ext.workspace = true
futures-lite.workspace = true
log.workspace = true
once_cell.workspace = true
pyo3 = { workspace = true, features = ["abi3-py38", "extension-module"] }
pyo3 = { workspace = true, features = ["abi3-py310", "extension-module"] }
pyo3-asyncio = { workspace = true, features = ["tokio-runtime"] }
pyo3-log.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand Down
24 changes: 12 additions & 12 deletions crates/voicevox_core_python_api/python/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
from pathlib import Path
from typing import List, TypedDict
from typing import TypedDict

import pytest
import voicevox_core
Expand All @@ -27,26 +27,26 @@

class DurationExampleData(TypedDict):
length: int
phoneme_vector: List[int]
result: List[float]
phoneme_vector: list[int]
result: list[float]


class IntonationExampleData(TypedDict):
length: int
vowel_phoneme_vector: List[int]
consonant_phoneme_vector: List[int]
start_accent_vector: List[int]
end_accent_vector: List[int]
start_accent_phrase_vector: List[int]
end_accent_phrase_vector: List[int]
result: List[float]
vowel_phoneme_vector: list[int]
consonant_phoneme_vector: list[int]
start_accent_vector: list[int]
end_accent_vector: list[int]
start_accent_phrase_vector: list[int]
end_accent_phrase_vector: list[int]
result: list[float]


class DecodeExampleData(TypedDict):
f0_length: int
phoneme_size: int
f0_vector: List[float]
phoneme_vector: List[float]
f0_vector: list[float]
phoneme_vector: list[float]


class ExampleData(TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ast
from ast import AnnAssign, ClassDef, Constant, Name
from pathlib import Path
from typing import Tuple

import voicevox_core

Expand All @@ -22,7 +21,7 @@ def test() -> None:
assert len({REAL_BLOCKING, REAL_ASYNCIO, stub_blocking, stub_asyncio}) == 1


def extract(pyi: Path) -> Tuple[str, str]:
def extract(pyi: Path) -> tuple[str, str]:
module = ast.parse(pyi.read_text(encoding="utf-8"))
class_def = next(
stmt
Expand Down
20 changes: 10 additions & 10 deletions crates/voicevox_core_python_api/python/voicevox_core/_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dataclasses
from enum import Enum
from typing import List, NewType, Optional
from typing import NewType
from uuid import UUID

import pydantic
Expand Down Expand Up @@ -64,7 +64,7 @@ class StyleMeta:
type: StyleType = dataclasses.field(default=StyleType.TALK)
"""スタイルに対応するモデルの種類。"""

order: Optional[int] = None
order: int | None = None
"""
話者の順番。
Expand All @@ -79,7 +79,7 @@ class SpeakerMeta:
name: str
"""話者名。"""

styles: List[StyleMeta]
styles: list[StyleMeta]
"""話者に属するスタイル。"""

speaker_uuid: str
Expand All @@ -88,7 +88,7 @@ class SpeakerMeta:
version: StyleVersion
"""話者のUUID。"""

order: Optional[int] = None
order: int | None = None
"""
話者の順番。
Expand Down Expand Up @@ -162,24 +162,24 @@ class Mora:
pitch: float
"""音高。"""

consonant: Optional[str] = None
consonant: str | None = None
"""子音の音素。"""

consonant_length: Optional[float] = None
consonant_length: float | None = None
"""子音の音長。"""


@pydantic.dataclasses.dataclass
class AccentPhrase:
"""AccentPhrase (アクセント句ごとの情報)。"""

moras: List[Mora]
moras: list[Mora]
"""モーラの配列。"""

accent: int
"""アクセント箇所。"""

pause_mora: Optional[Mora] = None
pause_mora: Mora | None = None
"""後ろに無音を付けるかどうか。"""

is_interrogative: bool = False
Expand All @@ -190,7 +190,7 @@ class AccentPhrase:
class AudioQuery:
"""AudioQuery (音声合成用のクエリ)。"""

accent_phrases: List[AccentPhrase]
accent_phrases: list[AccentPhrase]
"""アクセント句の配列。"""

speed_scale: float
Expand Down Expand Up @@ -223,7 +223,7 @@ class AudioQuery:
pause_length_scale: float = 1.0
"""読点などの無音時間(倍率)。デフォルト値は ``1.0`` 。"""

kana: Optional[str] = None
kana: str | None = None
"""
[読み取り専用] AquesTalk風記法。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import PathLike
from typing import TYPE_CHECKING, Dict, List, Literal, Union
from typing import TYPE_CHECKING, Literal, Union
from uuid import UUID

if TYPE_CHECKING:
Expand All @@ -19,7 +19,7 @@ class VoiceModelFile:
音声モデルファイル。"""

@staticmethod
async def open(path: Union[str, PathLike[str]]) -> VoiceModelFile:
async def open(path: str | PathLike[str]) -> VoiceModelFile:
"""
VVMファイルを開く。
Expand All @@ -42,7 +42,7 @@ class VoiceModelFile:
"""ID。"""
...
@property
def metas(self) -> List[SpeakerMeta]:
def metas(self) -> list[SpeakerMeta]:
"""
メタ情報。
Expand Down Expand Up @@ -125,7 +125,7 @@ class OpenJtalk:
"""

@staticmethod
async def new(open_jtalk_dict_dir: Union[str, PathLike[str]]) -> "OpenJtalk":
async def new(open_jtalk_dict_dir: str | PathLike[str]) -> "OpenJtalk":
"""
``OpenJTalk`` を生成する。
Expand Down Expand Up @@ -169,9 +169,8 @@ class Synthesizer:
self,
onnxruntime: Onnxruntime,
open_jtalk: OpenJtalk,
acceleration_mode: Union[
AccelerationMode, Literal["AUTO", "CPU", "GPU"]
] = AccelerationMode.AUTO,
acceleration_mode: AccelerationMode
| Literal["AUTO", "CPU", "GPU"] = AccelerationMode.AUTO,
cpu_num_threads: int = 0,
) -> None: ...
def __repr__(self) -> str: ...
Expand All @@ -185,7 +184,7 @@ class Synthesizer:
def is_gpu_mode(self) -> bool:
"""ハードウェアアクセラレーションがGPUモードかどうか。"""
...
def metas(self) -> List[SpeakerMeta]:
def metas(self) -> list[SpeakerMeta]:
"""メタ情報。"""
...
async def load_voice_model(self, model: VoiceModelFile) -> None:
Expand All @@ -198,7 +197,7 @@ class Synthesizer:
読み込むモデルのスタイルID。
"""
...
def unload_voice_model(self, voice_model_id: Union[VoiceModelId, UUID]) -> None:
def unload_voice_model(self, voice_model_id: VoiceModelId | UUID) -> None:
"""
音声モデルの読み込みを解除する。
Expand All @@ -208,7 +207,7 @@ class Synthesizer:
音声モデルID。
"""
...
def is_loaded_voice_model(self, voice_model_id: Union[VoiceModelId, UUID]) -> bool:
def is_loaded_voice_model(self, voice_model_id: VoiceModelId | UUID) -> bool:
"""
指定したvoice_model_idのモデルが読み込まれているか判定する。
Expand All @@ -225,7 +224,7 @@ class Synthesizer:
async def create_audio_query_from_kana(
self,
kana: str,
style_id: Union[StyleId, int],
style_id: StyleId | int,
) -> AudioQuery:
"""
AquesTalk風記法から :class:`AudioQuery` を生成する。
Expand All @@ -245,7 +244,7 @@ class Synthesizer:
async def create_audio_query(
self,
text: str,
style_id: Union[StyleId, int],
style_id: StyleId | int,
) -> AudioQuery:
"""
日本語のテキストから :class:`AudioQuery` を生成する。
Expand All @@ -265,8 +264,8 @@ class Synthesizer:
async def create_accent_phrases_from_kana(
self,
kana: str,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
style_id: StyleId | int,
) -> list[AccentPhrase]:
"""
AquesTalk風記法からAccentPhrase(アクセント句)の配列を生成する。
Expand All @@ -285,8 +284,8 @@ class Synthesizer:
async def create_accent_phrases(
self,
text: str,
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
style_id: StyleId | int,
) -> list[AccentPhrase]:
"""
日本語のテキストからAccentPhrase(アクセント句)の配列を生成する。
Expand All @@ -304,9 +303,9 @@ class Synthesizer:
...
async def replace_mora_data(
self,
accent_phrases: List[AccentPhrase],
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
accent_phrases: list[AccentPhrase],
style_id: StyleId | int,
) -> list[AccentPhrase]:
"""
アクセント句の音高・音素長を変更した新しいアクセント句の配列を生成する。
Expand All @@ -326,9 +325,9 @@ class Synthesizer:
...
async def replace_phoneme_length(
self,
accent_phrases: List[AccentPhrase],
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
accent_phrases: list[AccentPhrase],
style_id: StyleId | int,
) -> list[AccentPhrase]:
"""
アクセント句の音素長を変更した新しいアクセント句の配列を生成する。
Expand All @@ -344,9 +343,9 @@ class Synthesizer:
...
async def replace_mora_pitch(
self,
accent_phrases: List[AccentPhrase],
style_id: Union[StyleId, int],
) -> List[AccentPhrase]:
accent_phrases: list[AccentPhrase],
style_id: StyleId | int,
) -> list[AccentPhrase]:
"""
アクセント句の音高を変更した新しいアクセント句の配列を生成する。
Expand All @@ -363,7 +362,7 @@ class Synthesizer:
async def synthesis(
self,
audio_query: AudioQuery,
style_id: Union[StyleId, int],
style_id: StyleId | int,
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand All @@ -386,7 +385,7 @@ class Synthesizer:
async def tts_from_kana(
self,
kana: str,
style_id: Union[StyleId, int],
style_id: StyleId | int,
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand All @@ -405,7 +404,7 @@ class Synthesizer:
async def tts(
self,
text: str,
style_id: Union[StyleId, int],
style_id: StyleId | int,
enable_interrogative_upspeak: bool = True,
) -> bytes:
"""
Expand All @@ -430,11 +429,11 @@ class Synthesizer:
class UserDict:
"""ユーザー辞書。"""

def words(self) -> Dict[UUID, UserDictWord]:
def words(self) -> dict[UUID, UserDictWord]:
"""このオプジェクトの :class:`dict` としての表現。"""
...
def __init__(self) -> None: ...
async def load(self, path: Union[str, PathLike[str]]) -> None:
async def load(self, path: str | PathLike[str]) -> None:
"""ファイルに保存されたユーザー辞書を読み込む。
Parameters
Expand All @@ -443,7 +442,7 @@ class UserDict:
ユーザー辞書のパス。
"""
...
async def save(self, path: Union[str, PathLike[str]]) -> None:
async def save(self, path: str | PathLike[str]) -> None:
"""
ユーザー辞書をファイルに保存する。
Expand Down
Loading

0 comments on commit 20c6c43

Please sign in to comment.