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

Added some parts related to /speaker_info endpoint. #20

Merged
merged 6 commits into from
Mar 22, 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
23 changes: 22 additions & 1 deletion voicevox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .audio_query import AudioQuery
from .http import HttpClient
from .speakers import Speaker

from .speaker_info import SpeakerInfo

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -128,6 +128,27 @@ async def fetch_speakers(
"""
speakers = await self.http.get_speakers(core_version)
return [Speaker(speaker) for speaker in speakers]

async def fetch_speaker_info(
self, speaker_uuid: str, core_version: Optional[str] = None
) -> SpeakerInfo:
"""Fetch speaker's info by given uuid.

This function retrieves additional information about a specific speaker, including its voice samples, icon, and portrait images.

Parameters
----------
speaker_uuid : str
speaker's uuid
core_version : Optional[str]
voicevox core version

AbstractUmbra marked this conversation as resolved.
Show resolved Hide resolved
Returns
-------
SpeakerInfo
Contains additional information of the speaker.
"""
return SpeakerInfo(await self.http.get_speaker_info(speaker_uuid, core_version))

async def multi_synthesis(
self, audio_queries: List[AudioQuery], speaker: int,
Expand Down
12 changes: 12 additions & 0 deletions voicevox/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from httpx import AsyncClient


from .errors import NotfoundError, HttpException
from .types import AudioQueryType, SpeakerType
from .types.speaker_info import SpeakerInfoType


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -79,6 +81,16 @@ async def get_speakers(
params["core_version"] = core_version
return await self.request("GET", "/speakers", params=params)

async def get_speaker_info(
self, speaker_uuid: str, core_version: Optional[str]
) -> SpeakerInfoType:
params = {
"speaker_uuid": speaker_uuid
}
if core_version is not None:
params["core_version"] = core_version
return await self.request("GET", "/speaker_info", params=params)

async def initialize_speaker(self, params: dict) -> None:
await self.request("POST", "/initialize_speaker", params=params)

Expand Down
61 changes: 61 additions & 0 deletions voicevox/speaker_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# voicevox - speaker_info

from typing import List

from .types.speaker_info import SpeakerInfoType, StyleInfoType

Alacadrial marked this conversation as resolved.
Show resolved Hide resolved

class StyleInfo:
"""Return style info

Attributes
----------
id: int
style id
icon: str
base64 encoded icon
portrait: str
base64 encoded portrait image
voice_samples: list[str]
base64 encoded voice sample
"""

def __init__(self, payload: StyleInfoType):
self.__data = payload

@property
def id(self) -> int:
return self.__data["id"]
Alacadrial marked this conversation as resolved.
Show resolved Hide resolved

@property
def icon(self) -> str:
return self.__data["icon"]

@property
Alacadrial marked this conversation as resolved.
Show resolved Hide resolved
def portrait(self) -> str:
return self.__data["portrait"]

@property
Alacadrial marked this conversation as resolved.
Show resolved Hide resolved
def voice_samples(self) -> list[str]:
return self.__data["voice_samples"]

AbstractUmbra marked this conversation as resolved.
Show resolved Hide resolved

class SpeakerInfo:
"""Return speaker info

Attributes
----------
policy: str
policy
portrait: str
base64 encoded portrait image
style_infos: list[StyleInfo]
list of Style informations
"""

def __init__(self, payload: SpeakerInfoType):
self.policy: str = payload["policy"]
self.portrait: str = payload["portrait"]
self.style_infos: List[StyleInfo] = [
StyleInfo(style_info) for style_info in payload["style_infos"]
]
16 changes: 16 additions & 0 deletions voicevox/types/speaker_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# voicevox - types/speaker_info

from typing import TypedDict, List


class StyleInfoType(TypedDict):
id: int
icon: str
portrait: str
voice_samples: List[str]


class SpeakerInfoType(TypedDict):
policy: str
portrait: str
style_infos: List[StyleInfoType]