diff --git a/README.rst b/README.rst index d4c99aa..f396f95 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,7 @@ Example .. code:: python - from voicevox import Client + from vvclient import Client import asyncio diff --git a/examples/basic.py b/examples/basic.py index 6e9c14d..1ae65a0 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -1,4 +1,4 @@ -from voicevox import Client +from vvclient import Client import asyncio diff --git a/examples/get_speakers.py b/examples/get_speakers.py index 410b3f8..953df73 100644 --- a/examples/get_speakers.py +++ b/examples/get_speakers.py @@ -1,4 +1,4 @@ -from voicevox import Client +from vvclient import Client import asyncio diff --git a/examples/multi_synthesis.py b/examples/multi_synthesis.py index f7eb385..31d0643 100644 --- a/examples/multi_synthesis.py +++ b/examples/multi_synthesis.py @@ -1,4 +1,4 @@ -from voicevox import Client +from vvclient import Client import asyncio diff --git a/tests/test_basic.py b/tests/test_basic.py index 7aa2573..1c8a262 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,10 +1,10 @@ import pytest -from voicevox import Client +from vvclient import Client @pytest.mark.asyncio async def test_basic(): async with Client() as client: - audio_query = await client.create_audio_query("こんにちは!", style_id=1) - await audio_query.synthesis(style_id=1) + audio_query = await client.create_audio_query("こんにちは!", speaker=1) + await audio_query.synthesis(speaker=1) diff --git a/tests/test_fetch_version.py b/tests/test_fetch_version.py index f144fa6..5f815ca 100644 --- a/tests/test_fetch_version.py +++ b/tests/test_fetch_version.py @@ -1,6 +1,6 @@ import pytest -from voicevox import Client +from vvclient import Client @pytest.mark.asyncio diff --git a/tests/test_init.py b/tests/test_init.py index 43ab4a5..e32e5d7 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,6 +1,6 @@ import pytest -from voicevox import Client +from vvclient import Client @pytest.mark.asyncio diff --git a/vvclient/audio_query.py b/vvclient/audio_query.py index 6f1a718..2ac8107 100644 --- a/vvclient/audio_query.py +++ b/vvclient/audio_query.py @@ -20,8 +20,8 @@ async def synthesis( ) -> bytes: params = { "speaker": speaker, - "enable_interrogative_upspeak": enable_interrogative_upspeak, + "enable_interrogative_upspeak": "true" if enable_interrogative_upspeak else "false", } if core_version: params["core_version"] = core_version - return await self._http.create_audio_query(params, self.data) + return await self._http.synthesis(params, self.data) diff --git a/vvclient/client.py b/vvclient/client.py index 0e362f8..e3967a6 100644 --- a/vvclient/client.py +++ b/vvclient/client.py @@ -3,6 +3,7 @@ from typing import Optional from .http import HTTPClient +from .audio_query import AudioQuery class Client: @@ -12,15 +13,39 @@ class Client: ---------- base_uri : str Base URI of the VOICEVOX Engine""" - def __init__(self, base_uri: str) -> None: + def __init__(self, base_uri: str = "http://localhost:50021") -> None: self.http = HTTPClient(base_uri) + async def __aenter__(self) -> "Client": + return self + + async def __aexit__(self, *args): + await self.close() + async def close(self) -> None: await self.http.close() async def create_audio_query( self, text: str, speaker: int, *, core_version: Optional[str] = None - ): + ) -> AudioQuery: + """ + Create audio query + + Parameters + ---------- + text: str + Voice text + speaker: int + speaker type + core_version: Optional[str] + voicevox_core version + + Returns + ------- + audio_query: AudioQuery + Audio query + """ params = {"text": text, "speaker": speaker} if core_version: params["core_version"] = core_version + return AudioQuery(self.http, await self.http.create_audio_query(params)) diff --git a/vvclient/http.py b/vvclient/http.py index 5f9d0c2..5fd882d 100644 --- a/vvclient/http.py +++ b/vvclient/http.py @@ -31,7 +31,7 @@ async def request(self, route: Route, **kwargs) -> Any: return await response.json() else: return await response.read() - elif res.status == 404: + elif response.status == 404: raise NotFoundError("Not found") else: raise HTTPException(await response.text(), response.status) @@ -42,7 +42,7 @@ async def close(self) -> None: async def create_audio_query( self, params: Dict[str, Union[str, int]] ) -> AudioQueryType: - return await self.request(Route("POST", "/audio_query"), json=params) + return await self.request(Route("POST", "/audio_query"), params=params) async def synthesis( self, params: Dict[str, Union[str, int]], audio_query: AudioQueryType