Skip to content

Commit 3efaf42

Browse files
committed
Enhance VOICEVOX Docker support with flexible deployment options
- Add docker_only option for launching Docker container without ROS sound_play node - Add remote connection support with automatic local/remote detection - Improve README with detailed usage examples for different deployment scenarios - Fix host binding issues to prevent port conflicts when connecting to remote containers - Support GPU acceleration with proper documentation Features: - docker_only: Launch only Docker container (useful for server deployment) - Automatic local/remote detection based on host parameter - Enhanced run-voicevox-docker script with remote connection handling - Comprehensive documentation for all usage patterns
1 parent eba09aa commit 3efaf42

File tree

4 files changed

+199
-12
lines changed

4 files changed

+199
-12
lines changed

3rdparty/voicevox/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ endif()
9191
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bin/run-voicevox.in
9292
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/bin/run-voicevox
9393
@ONLY)
94+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bin/run-voicevox-docker.in
95+
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/bin/run-voicevox-docker
96+
@ONLY)
9497

9598

9699
catkin_install_python(
97100
PROGRAMS node_scripts/request_synthesis.py node_scripts/list_speakers.py
98101
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/node_scripts/)
99102
install(
100-
PROGRAMS bin/text2wave ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/bin/run-voicevox
103+
PROGRAMS bin/text2wave ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/bin/run-voicevox ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/bin/run-voicevox-docker
101104
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/bin)
102105

103106
install(DIRECTORY launch

3rdparty/voicevox/README.md

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
ROS Interface for [VOICEVOX](https://voicevox.hiroshiba.jp/) (AI speech synthesis)
44

5+
## Quick Start
6+
7+
Choose the deployment pattern that best fits your needs:
8+
9+
```bash
10+
# Pattern A: Direct Docker + ROS client (Multi-machine) | 直接Docker + ROSクライアント(マルチマシン)
11+
# Server machine:
12+
docker run --rm --gpus all -p '50021:50021' voicevox/voicevox_engine:nvidia-ubuntu20.04-latest
13+
# Client machine:
14+
roslaunch voicevox voicevox_texttospeech.launch host:=<server_ip> port:=50021
15+
16+
# Pattern B: ROS-managed Docker + ROS client (Multi-machine) | ROS管理Docker + ROSクライアント(マルチマシン)
17+
# Server machine:
18+
roslaunch voicevox voicevox_texttospeech.launch docker_only:=true
19+
# Client machine:
20+
roslaunch voicevox voicevox_texttospeech.launch host:=<server_ip> port:=50021
21+
22+
# Pattern C: All-in-one (Docker + ROS on same machine) | オールインワン(同一マシンでDocker+ROS)
23+
roslaunch voicevox voicevox_texttospeech.launch use_docker:=true
24+
25+
# Pattern D: Local VOICEVOX without Docker (CPU only) | ローカルVOICEVOX(Dockerなし、CPU版)
26+
# VOICEVOX engine is automatically installed during catkin build
27+
roslaunch voicevox voicevox_texttospeech.launch
28+
```
29+
30+
Patterns A-C provide GPU acceleration support through Docker. Pattern D runs locally with CPU only.
31+
パターンA-CはDockerを通じたGPUによる高速な音声合成をサポート。パターンDはCPUのみでローカル実行。
32+
533
## TERM
634

735
[VOICEVOX](https://voicevox.hiroshiba.jp/) is basically free to use, but please check the terms of use below.
@@ -55,29 +83,73 @@ cd /path/to/catkin_workspace
5583
catkin build voicevox
5684
```
5785

58-
### Optional (Using docker with GPU)
86+
### Optional (Using Docker with GPU acceleration)
87+
88+
VOICEVOX supports Docker deployment with GPU acceleration, which enables significantly faster speech synthesis compared to CPU-only processing.
89+
90+
#### Prerequisites
5991

60-
First, install the NVIDIA Container Toolkit.
92+
First, install the NVIDIA Container Toolkit:
6193

6294
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
6395

64-
After that,
96+
#### Setup
6597

66-
```
98+
Pull the GPU-enabled VOICEVOX Docker image:
99+
100+
```bash
67101
docker pull voicevox/voicevox_engine:nvidia-ubuntu20.04-latest
68102
```
69103

104+
Start the Docker container with GPU support:
70105

71-
You should start Docker as follows.
72-
73-
```
106+
```bash
74107
docker run --rm --gpus all -p '50021:50021' voicevox/voicevox_engine:nvidia-ubuntu20.04-latest
75108
```
76109

77-
```
110+
#### Usage with use_docker option
111+
112+
Launch the ROS node with Docker backend using the `use_docker:=true` option:
113+
114+
```bash
115+
# For local Docker container
116+
roslaunch voicevox voicevox_texttospeech.launch use_docker:=true
117+
118+
# For remote Docker container
78119
roslaunch voicevox voicevox_texttospeech.launch use_docker:=true host:=<Docker PC IP>
79120
```
80121

122+
#### Docker-only mode
123+
124+
If you want to launch only the Docker container without the ROS sound_play node, use the `docker_only:=true` option:
125+
126+
```bash
127+
# Launch Docker container only (local)
128+
roslaunch voicevox voicevox_texttospeech.launch docker_only:=true
129+
130+
# Launch Docker container only with custom port
131+
roslaunch voicevox voicevox_texttospeech.launch docker_only:=true port:=50022
132+
```
133+
134+
#### Connect to existing Docker container
135+
136+
To connect to an existing Docker container running on a different machine:
137+
138+
```bash
139+
# Connect to remote Docker container
140+
roslaunch voicevox voicevox_texttospeech.launch host:=<Docker PC IP> port:=<Docker Port>
141+
142+
# Example: Connect to Docker container at 192.168.1.100:50021
143+
roslaunch voicevox voicevox_texttospeech.launch host:=192.168.1.100 port:=50021
144+
```
145+
146+
The `use_docker` and `docker_only` options allow you to:
147+
- **use_docker**: Run Docker container and ROS node together
148+
- **docker_only**: Launch only the Docker container (useful for server deployment)
149+
- Utilize GPU acceleration for faster speech synthesis
150+
- Run VOICEVOX engine in an isolated container environment
151+
- Easily deploy on different machines without local installation
152+
81153

82154
## Usage
83155

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
# Original arguments
4+
args=("$@")
5+
6+
# Filtered arguments (up to first "--")
7+
filtered_args=()
8+
for arg in "${args[@]}"; do
9+
if [[ "$arg" == -- ]]; then
10+
break
11+
fi
12+
filtered_args+=("$arg")
13+
done
14+
15+
# Extract arguments for docker run
16+
host="localhost"
17+
port="50021"
18+
cpu_num_threads="1"
19+
20+
# Parse arguments
21+
while [[ $# -gt 0 ]]; do
22+
case $1 in
23+
--host)
24+
host="$2"
25+
shift 2
26+
;;
27+
--port)
28+
port="$2"
29+
shift 2
30+
;;
31+
--cpu_num_threads)
32+
cpu_num_threads="$2"
33+
shift 2
34+
;;
35+
--)
36+
shift
37+
break
38+
;;
39+
*)
40+
shift
41+
;;
42+
esac
43+
done
44+
45+
# Check if host is localhost (start local container) or remote (just wait)
46+
if [[ "$host" == "localhost" || "$host" == "127.0.0.1" ]]; then
47+
# Local Docker container mode
48+
container_name="voicevox-engine-${port}"
49+
if docker ps | grep -q "$container_name"; then
50+
echo "VOICEVOX Docker container is already running on port $port"
51+
# Keep the container running
52+
docker logs -f "$container_name"
53+
exit 0
54+
fi
55+
56+
# Remove any existing stopped container with the same name
57+
docker rm -f "$container_name" 2>/dev/null || true
58+
59+
# Check if voicevox image exists, if not pull it
60+
if ! docker images | grep -q "voicevox/voicevox_engine"; then
61+
echo "Pulling VOICEVOX Docker image..."
62+
docker pull voicevox/voicevox_engine:latest
63+
fi
64+
65+
# Run VOICEVOX Docker container
66+
echo "Starting VOICEVOX Docker container on port $port with $cpu_num_threads CPU threads..."
67+
exec docker run --rm \
68+
--name "$container_name" \
69+
-p "$port:50021" \
70+
-e CPU_NUM_THREADS="$cpu_num_threads" \
71+
voicevox/voicevox_engine:cpu-ubuntu20.04-latest
72+
else
73+
# Remote Docker container mode - just wait for connection
74+
echo "Connecting to remote VOICEVOX Docker container at $host:$port"
75+
echo "Make sure the Docker container is running on the remote host with:"
76+
echo "docker run --rm --gpus all -p '$port:50021' voicevox/voicevox_engine:nvidia-ubuntu20.04-latest"
77+
echo ""
78+
echo "Waiting for connection to $host:$port..."
79+
80+
# Wait for the remote service to be available
81+
while true; do
82+
if curl -s --connect-timeout 5 "http://$host:$port/docs" > /dev/null 2>&1; then
83+
echo "Successfully connected to VOICEVOX engine at $host:$port"
84+
break
85+
else
86+
echo "Waiting for VOICEVOX engine at $host:$port..."
87+
sleep 5
88+
fi
89+
done
90+
91+
# Keep the script running
92+
echo "VOICEVOX engine is ready at $host:$port"
93+
while true; do
94+
sleep 30
95+
if ! curl -s --connect-timeout 5 "http://$host:$port/docs" > /dev/null 2>&1; then
96+
echo "Lost connection to VOICEVOX engine at $host:$port"
97+
exit 1
98+
fi
99+
done
100+
fi

3rdparty/voicevox/launch/voicevox_texttospeech.launch

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@
1212
doc="Number of cpu threads" />
1313
<arg name="use_docker" default="false"
1414
doc="Use docker or not (default: false)" />
15+
<arg name="docker_only" default="false"
16+
doc="Launch only docker container without sound_play node (default: false)" />
17+
<arg name="remote_only" default="false"
18+
doc="Connect to remote server without starting local server (default: false)" />
1519

1620
<node name="voicevox_server"
1721
pkg="voicevox" type="run-voicevox"
18-
args="--voicelib_dir=$(find voicevox)/voicevox_core --host $(arg host) --port $(arg port) --cpu_num_threads=$(arg cpu_num_threads) --load_all_models --"
22+
args="--voicelib_dir=$(find voicevox)/voicevox_core --host 0.0.0.0 --port $(arg port) --cpu_num_threads=$(arg cpu_num_threads) --load_all_models --"
1923
respawn="$(arg sound_play_respawn)"
2024
output="screen"
21-
unless="$(arg use_docker)">
25+
unless="$(eval arg('use_docker') or arg('docker_only') or arg('remote_only') or (arg('host') != 'localhost' and arg('host') != '127.0.0.1'))">
2226
</node>
2327

24-
<node if="$(arg launch_sound_play)"
28+
<node name="voicevox_docker_server"
29+
pkg="voicevox" type="run-voicevox-docker"
30+
args="--host $(arg host) --port $(arg port) --cpu_num_threads=$(arg cpu_num_threads) --"
31+
respawn="$(arg sound_play_respawn)"
32+
output="screen"
33+
if="$(eval arg('use_docker') or arg('docker_only'))">
34+
</node>
35+
36+
<node if="$(eval arg('launch_sound_play') and not arg('docker_only'))"
2537
name="sound_play_jp"
2638
pkg="sound_play" type="soundplay_node.py"
2739
respawn="$(arg sound_play_respawn)"

0 commit comments

Comments
 (0)