Skip to content

Commit 1c470a0

Browse files
committed
Enhance VOICEVOX client and examples with improved functionality and Docker support
- Updated Client initialization to accept base_uri parameter. - Modified main example to use the new Client initialization. - Improved formatting in audio_query.py for better readability. - Added Dockerfile and docker-compose.yml for containerized development. - Created devcontainer.json for seamless integration with development environments.
1 parent 02daee4 commit 1c470a0

File tree

8 files changed

+71
-14
lines changed

8 files changed

+71
-14
lines changed

.devcontainer/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Note: You can use any Debian/Ubuntu based image you want.
2+
FROM mcr.microsoft.com/devcontainers/python:3.13
3+
4+
# [Optional] Uncomment this section to install additional OS packages.
5+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
# && apt-get -y install --no-install-recommends <your-package-list-here>

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-outside-of-docker-compose
3+
{
4+
"name": "Docker from Docker Compose",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
9+
// Use this environment variable if you need to bind mount your local source code into a new container.
10+
"remoteEnv": {
11+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
12+
},
13+
14+
"features": {}
15+
}

.devcontainer/docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- ../..:/workspaces:cached
10+
command: sleep infinity
11+
networks:
12+
- main
13+
14+
voicevox:
15+
image: voicevox/voicevox_engine:cpu-latest
16+
networks:
17+
- main
18+
19+
networks:
20+
main:

examples/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
async def main():
6-
async with Client() as client:
6+
async with Client(base_uri="http://voicevox:50021") as client:
77
audio_query = await client.create_audio_query("こんにちは!", speaker=1)
88
with open("voice.wav", "wb") as f:
99
f.write(await audio_query.synthesis(speaker=1))

vvclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44

55
__version__ = "1.0.0a"
6-
__all__ = ["Client"]
6+
__all__ = ["Client"]

vvclient/audio_query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ async def synthesis(
2020
) -> bytes:
2121
params = {
2222
"speaker": speaker,
23-
"enable_interrogative_upspeak": "true" if enable_interrogative_upspeak else "false",
23+
"enable_interrogative_upspeak": (
24+
"true" if enable_interrogative_upspeak else "false"
25+
),
2426
}
2527
if core_version:
2628
params["core_version"] = core_version

vvclient/client.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
class Client:
1010
"""VOICEVOX Engine client
11-
11+
1212
Parameters
1313
----------
1414
base_uri : str
1515
Base URI of the VOICEVOX Engine"""
16+
1617
def __init__(self, base_uri: str = "http://localhost:50021") -> None:
1718
self.http = HTTPClient(base_uri)
1819

@@ -26,7 +27,12 @@ async def close(self) -> None:
2627
await self.http.close()
2728

2829
async def create_audio_query(
29-
self, text: str, speaker: int, *, core_version: Optional[str] = None
30+
self,
31+
text: str,
32+
speaker: int,
33+
*,
34+
core_version: Optional[str] = None,
35+
enable_katakana_english: bool = True
3036
) -> AudioQuery:
3137
"""
3238
Create audio query
@@ -39,6 +45,8 @@ async def create_audio_query(
3945
speaker type
4046
core_version: Optional[str]
4147
voicevox_core version
48+
enable_katakana_english: bool
49+
Enable Katakana English (Default is True)
4250
4351
Returns
4452
-------
@@ -72,7 +80,13 @@ async def fetch_core_versions(self) -> List[str]:
7280
"""
7381
return await self.http.core_versions()
7482

75-
async def init_speaker(self, speaker: int, *, skip_reinit: bool = False, core_version: Optional[str] = None) -> None:
83+
async def init_speaker(
84+
self,
85+
speaker: int,
86+
*,
87+
skip_reinit: bool = False,
88+
core_version: Optional[str] = None
89+
) -> None:
7690
"""
7791
Initialize speaker
7892
@@ -85,19 +99,17 @@ async def init_speaker(self, speaker: int, *, skip_reinit: bool = False, core_ve
8599
core_version: Optional[str]
86100
VOICEVOX Core version
87101
"""
88-
params = {
89-
"speaker": speaker
90-
}
102+
params = {"speaker": speaker}
91103
if skip_reinit:
92104
params["skip_reinit"] = "true"
93105
if core_version:
94106
params["core_version"] = core_version
95107
await self.http.initialize_speaker(params)
96108

97-
async def is_inited_speaker(self, speaker: int, *, core_version: Optional[str] = None) -> bool:
98-
params = {
99-
"speaker": speaker
100-
}
109+
async def is_inited_speaker(
110+
self, speaker: int, *, core_version: Optional[str] = None
111+
) -> bool:
112+
params = {"speaker": speaker}
101113
if core_version:
102114
params["core_version"] = core_version
103115
return await self.http.is_initialized_speaker(params)

vvclient/http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@ async def initialize_speaker(self, params: Dict[str, Union[str, int]]) -> None:
6363
return await self.request(Route("POST", "/initialize_speaker"), params=params)
6464

6565
async def is_initialized_speaker(self, params: Dict[str, Union[str, int]]) -> bool:
66-
return await self.request(Route("GET", "/is_initialized_speaker"), params=params)
66+
return await self.request(
67+
Route("GET", "/is_initialized_speaker"), params=params
68+
)

0 commit comments

Comments
 (0)