Skip to content

Commit 4d22817

Browse files
committed
fix types and format
1 parent e356ee2 commit 4d22817

File tree

12 files changed

+78
-104
lines changed

12 files changed

+78
-104
lines changed

examples/basic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
async def main():
66
async with Client() as client:
7-
audio_query = await client.create_audio_query(
8-
"こんにちは!", speaker=1
9-
)
7+
audio_query = await client.create_audio_query("こんにちは!", speaker=1)
108
with open("voice.wav", "wb") as f:
119
f.write(await audio_query.synthesis(speaker=1))
1210

examples/multi_synthesis.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ async def main():
66
audio_queries = []
77
async with Client() as client:
88
for text in ["おはようございます!", "こんにちは!"]:
9-
audio_queries.append(await client.create_audio_query(
10-
text, speaker=1
11-
))
9+
audio_queries.append(await client.create_audio_query(text, speaker=1))
1210
with open("audio.zip", "wb") as f:
1311
f.write(await client.multi_synthesis(audio_queries, speaker=1))
1412

tests/test_basic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
@pytest.mark.asyncio
77
async def test_basic():
88
async with Client() as client:
9-
audio_query = await client.create_audio_query(
10-
"こんにちは!", speaker=1
11-
)
9+
audio_query = await client.create_audio_query("こんにちは!", speaker=1)
1210
await audio_query.synthesis(speaker=1)

voicevox/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
__all__ = (
1313
"Client",
1414
"AudioQuery",
15-
"HttpException", "NotfoundError",
16-
"Speaker", "Style", "SupportedFeature"
15+
"HttpException",
16+
"NotfoundError",
17+
"Speaker",
18+
"Style",
19+
"SupportedFeature",
1720
)
1821
__version__ = "0.2.1"

voicevox/audio_query.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def __init__(self, payload: MoraType):
3030
self.text: str = payload["text"]
3131
self.consonant: str = payload["consonant"]
3232
self.consonant_length: int = payload["consonant_length"]
33-
self.vowel: int = payload["vowel"]
33+
self.vowel: str = payload["vowel"]
3434
self.vowel_length: int = payload["vowel_length"]
35-
self.pitch: int = payload["pitch"]
35+
self.pitch: float = payload["pitch"]
3636

3737
def to_dict(self) -> dict:
3838
return {
@@ -41,7 +41,7 @@ def to_dict(self) -> dict:
4141
"consonant_length": self.consonant_length,
4242
"vowel": self.vowel,
4343
"vowel_length": self.vowel_length,
44-
"pitch": self.pitch
44+
"pitch": self.pitch,
4545
}
4646

4747

@@ -74,7 +74,7 @@ def to_dict(self) -> AccentPhraseType:
7474
payload = {
7575
"moras": [mora.to_dict() for mora in self.moras],
7676
"accent": self.accent,
77-
"is_interrogative": self.is_interrogative
77+
"is_interrogative": self.is_interrogative,
7878
}
7979
if self.pause_mora is not None:
8080
payload["pause_mora"] = self.pause_mora.to_dict()
@@ -112,15 +112,12 @@ class AudioQuery:
112112
[読み取り専用]AquesTalkライクな読み仮名。音声合成クエリとしては無視される
113113
"""
114114

115-
def __init__(
116-
self, http: HttpClient, payload: AudioQueryType
117-
):
115+
def __init__(self, http: HttpClient, payload: AudioQueryType):
118116
self.http = http
119117
self.__data = payload
120118

121119
self.accent_phrases: List[AccentPhrase] = [
122-
AccentPhrase(accent_phrase)
123-
for accent_phrase in payload["accent_phrases"]
120+
AccentPhrase(accent_phrase) for accent_phrase in payload["accent_phrases"]
124121
]
125122
self.speed_scale: float = payload["speedScale"]
126123
self.pitch_scale: float = payload["pitchScale"]
@@ -138,8 +135,7 @@ def kana(self) -> str:
138135
def to_dict(self) -> AudioQueryType:
139136
return {
140137
"accent_phrases": [
141-
accent_phrase.to_dict()
142-
for accent_phrase in self.accent_phrases
138+
accent_phrase.to_dict() for accent_phrase in self.accent_phrases
143139
],
144140
"speedScale": self.speed_scale,
145141
"pitchScale": self.pitch_scale,
@@ -149,16 +145,19 @@ def to_dict(self) -> AudioQueryType:
149145
"postPhonemeLength": self.post_phoneme_length,
150146
"outputSamplingRate": self.output_sampling_rate,
151147
"outputStereo": self.output_stereo,
152-
"kana": self.kana
148+
"kana": self.kana,
153149
}
154150

155151
async def synthesis(
156-
self, *, enable_interrogative_upspeak: bool = True,
157-
speaker: int, core_version: Optional[str] = None
152+
self,
153+
*,
154+
enable_interrogative_upspeak: bool = True,
155+
speaker: int,
156+
core_version: Optional[str] = None,
158157
) -> bytes:
159158
params = {
160159
"speaker": speaker,
161-
"enable_interrogative_upspeak": enable_interrogative_upspeak
160+
"enable_interrogative_upspeak": enable_interrogative_upspeak,
162161
}
163162
if core_version is not None:
164163
params["core_version"] = core_version

voicevox/client.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class Client:
3232
You can customize timeout. If you use cpu mode, I recommend to use this.
3333
"""
3434

35-
def __init__(self, base_url: str = "http://localhost:50021", timeout: Optional[int] = None):
35+
def __init__(
36+
self, base_url: str = "http://localhost:50021", timeout: Optional[int] = None
37+
):
3638
self.http = HttpClient(base_url=base_url, timeout=timeout)
3739

3840
async def close(self) -> None:
@@ -70,10 +72,7 @@ async def create_audio_query(
7072
AudioQuery
7173
Audio query, that run synthesis.
7274
"""
73-
params = {
74-
"text": text,
75-
"speaker": speaker
76-
}
75+
params = {"text": text, "speaker": speaker}
7776
if core_version is not None:
7877
params["core_version"] = core_version
7978
audio_query = await self.http.create_audio_query(params)
@@ -83,10 +82,7 @@ async def create_audio_query(
8382
async def create_audio_query_from_preset(
8483
self, text: str, preset_id: int, *, core_version: Optional[str] = None
8584
) -> AudioQuery:
86-
params = {
87-
"text": text,
88-
"preset_id": preset_id
89-
}
85+
params = {"text": text, "preset_id": preset_id}
9086
if core_version is not None:
9187
params["core_version"] = core_version
9288
audio_query = await self.http.create_audio_query_from_preset(params)
@@ -116,9 +112,7 @@ async def fetch_core_versions(self) -> List[str]:
116112
"""
117113
return await self.http.get_core_versions()
118114

119-
async def fetch_speakers(
120-
self, core_version: Optional[str] = None
121-
) -> List[Speaker]:
115+
async def fetch_speakers(self, core_version: Optional[str] = None) -> List[Speaker]:
122116
"""Fetch speakers
123117
124118
This can fetch voicevox speakers.
@@ -130,7 +124,7 @@ async def fetch_speakers(
130124
"""
131125
speakers = await self.http.get_speakers(core_version)
132126
return [Speaker(speaker) for speaker in speakers]
133-
127+
134128
async def fetch_speaker_info(
135129
self, speaker_uuid: str, core_version: Optional[str] = None
136130
) -> SpeakerInfo:
@@ -150,17 +144,22 @@ async def fetch_speaker_info(
150144
SpeakerInfo
151145
Contains additional information of the speaker.
152146
"""
153-
return SpeakerInfo(await self.http.get_speaker_info(speaker_uuid, core_version))
147+
return SpeakerInfo(await self.http.get_speaker_info(speaker_uuid, core_version))
154148

155-
async def check_devices(self, core_version: Optional[str] = None) -> SupportedDevices:
149+
async def check_devices(
150+
self, core_version: Optional[str] = None
151+
) -> SupportedDevices:
156152
params = {}
157153
if core_version:
158154
params["core_version"] = core_version
159155
return SupportedDevices(await self.http.supported_devices(params))
160156

161157
async def multi_synthesis(
162-
self, audio_queries: List[AudioQuery], speaker: int,
163-
*, core_version: Optional[str] = None
158+
self,
159+
audio_queries: List[AudioQuery],
160+
speaker: int,
161+
*,
162+
core_version: Optional[str] = None
164163
) -> bytes:
165164
"""Multi synthe
166165
@@ -179,20 +178,18 @@ async def multi_synthesis(
179178
-------
180179
bytes
181180
Return zip file"""
182-
params = {
183-
"speaker": speaker
184-
}
181+
params = {"speaker": speaker}
185182
if core_version is not None:
186183
params["core_version"] = core_version
187184
return await self.http.multi_synthesis(
188-
params, [
189-
audio_query.to_dict()
190-
for audio_query in audio_queries
191-
]
185+
params, [audio_query.to_dict() for audio_query in audio_queries]
192186
)
193187

194188
async def init_speaker(
195-
self, speaker: int, *, skip_reinit: bool = False,
189+
self,
190+
speaker: int,
191+
*,
192+
skip_reinit: bool = False,
196193
core_version: Optional[str] = None
197194
) -> None:
198195
"""Initilize speaker
@@ -210,15 +207,14 @@ async def init_speaker(
210207
who have already been initialized
211208
core_version: Optional[str]
212209
core version"""
213-
params = {
214-
"speaker": speaker,
215-
"skip_reinit": skip_reinit
216-
}
210+
params = {"speaker": speaker, "skip_reinit": skip_reinit}
217211
if core_version is not None:
218212
params["core_version"] = core_version
219213
await self.http.initialize_speaker(params)
220214

221-
async def check_inited_speaker(self, speaker: int, *, core_version: Optional[str] = None):
215+
async def check_inited_speaker(
216+
self, speaker: int, *, core_version: Optional[str] = None
217+
):
222218
"""Check initialized speaker
223219
224220
Returns whether the speaker with the specified speaker_id is initialized or not.
@@ -234,9 +230,7 @@ async def check_inited_speaker(self, speaker: int, *, core_version: Optional[str
234230
-------
235231
bool
236232
If initialized speaker, it return `True`."""
237-
params = {
238-
"speaker": speaker
239-
}
233+
params = {"speaker": speaker}
240234
if core_version is not None:
241235
params["core_version"] = core_version
242236
return await self.http.is_initialized_speaker(params)

voicevox/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# voicevox - errors
22

3+
34
class HttpException(Exception):
45
pass
56

voicevox/http.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010
from .errors import NotfoundError, HttpException
1111
from .types import AudioQueryType, SpeakerType
12-
from .types.speaker_info import SpeakerInfoType
12+
from .types.speaker_info import SpeakerInfoType
1313

1414

1515
logger = logging.getLogger(__name__)
1616

1717

1818
class HttpClient:
19-
2019
def __init__(self, base_url: str, timeout: Optional[int] = None):
2120
self.session = AsyncClient(base_url=base_url, timeout=timeout)
2221
logger.debug("Start session.")
@@ -28,9 +27,10 @@ async def close(self) -> None:
2827
async def request(self, method: str, path: str, **kwargs) -> dict:
2928
logger.debug(f"Request: {method} Path: {path} kwargs: {kwargs}")
3029
response = await self.session.request(method, path, **kwargs)
31-
logger.debug("StatusCode: {0.status_code} Response: {0.content}".format(response))
32-
if response.status_code == 200 or \
33-
response.status_code == 204:
30+
logger.debug(
31+
"StatusCode: {0.status_code} Response: {0.content}".format(response)
32+
)
33+
if response.status_code == 200 or response.status_code == 204:
3434
if response.headers.get("content-type") == "application/json":
3535
return response.json()
3636
else:
@@ -41,42 +41,26 @@ async def request(self, method: str, path: str, **kwargs) -> dict:
4141
raise HttpException(response.json())
4242

4343
async def synthesis(self, params: dict, payload: dict) -> bytes:
44-
return await self.request(
45-
"POST", "/synthesis", params=params,
46-
json=payload
47-
)
44+
return await self.request("POST", "/synthesis", params=params, json=payload)
4845

49-
async def multi_synthesis(
50-
self, params: dict, payload: List[dict]
51-
) -> bytes:
46+
async def multi_synthesis(self, params: dict, payload: List[dict]) -> bytes:
5247
return await self.request(
53-
"POST", "/multi_synthesis", params=params,
54-
json=payload
48+
"POST", "/multi_synthesis", params=params, json=payload
5549
)
5650

5751
async def create_audio_query(self, params: dict) -> AudioQueryType:
58-
return await self.request(
59-
"POST", "/audio_query", params=params
60-
)
52+
return await self.request("POST", "/audio_query", params=params)
6153

62-
async def create_audio_query_from_preset(
63-
self, params: dict
64-
) -> AudioQueryType:
65-
return await self.request(
66-
"POST", "/audio_query_from_preset", params=params
67-
)
54+
async def create_audio_query_from_preset(self, params: dict) -> AudioQueryType:
55+
return await self.request("POST", "/audio_query_from_preset", params=params)
6856

6957
async def get_version(self) -> str:
70-
return await self.request(
71-
"GET", "/version"
72-
)
58+
return await self.request("GET", "/version")
7359

7460
async def get_core_versions(self) -> List[str]:
7561
return await self.request("GET", "/core_versions")
7662

77-
async def get_speakers(
78-
self, core_version: Optional[str]
79-
) -> List[SpeakerType]:
63+
async def get_speakers(self, core_version: Optional[str]) -> List[SpeakerType]:
8064
params = {}
8165
if core_version is not None:
8266
params["core_version"] = core_version
@@ -85,9 +69,7 @@ async def get_speakers(
8569
async def get_speaker_info(
8670
self, speaker_uuid: str, core_version: Optional[str]
8771
) -> SpeakerInfoType:
88-
params = {
89-
"speaker_uuid": speaker_uuid
90-
}
72+
params = {"speaker_uuid": speaker_uuid}
9173
if core_version is not None:
9274
params["core_version"] = core_version
9375
return await self.request("GET", "/speaker_info", params=params)

voicevox/speaker_info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def __init__(self, payload: StyleInfoType):
2626
@property
2727
def id(self) -> int:
2828
return self.__data["id"]
29-
29+
3030
@property
3131
def icon(self) -> str:
3232
return self.__data["icon"]
33-
33+
3434
@property
3535
def portrait(self) -> str:
3636
return self.__data["portrait"]
37-
37+
3838
@property
3939
def voice_samples(self) -> list[str]:
4040
return self.__data["voice_samples"]
41-
41+
4242

4343
class SpeakerInfo:
4444
"""Return speaker info

0 commit comments

Comments
 (0)