Skip to content

Commit 24b31cc

Browse files
committed
-Fixed espeak engagement on gpu
-Add default voice code setting and update language code resolution logic
1 parent 9b76ce2 commit 24b31cc

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

‎api/src/core/config.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Settings(BaseSettings):
1313
output_dir: str = "output"
1414
output_dir_size_limit_mb: float = 500.0 # Maximum size of output directory in MB
1515
default_voice: str = "af_heart"
16+
default_voice_code: str | None = None # If set, overrides the first letter of voice name, though api call param still takes precedence
1617
use_gpu: bool = True # Whether to use GPU acceleration if available
1718
allow_local_voice_saving: bool = (
1819
False # Whether to allow saving combined voices locally

‎api/src/inference/kokoro_v1.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ async def generate_from_tokens(
139139
await paths.save_voice_tensor(voice_tensor, temp_path)
140140
voice_path = temp_path
141141

142-
# Use provided lang_code or get from voice name
143-
pipeline_lang_code = lang_code if lang_code else voice_name[0].lower()
142+
# Use provided lang_code, settings voice code override, or first letter of voice name
143+
if lang_code: # api is given priority
144+
pipeline_lang_code = lang_code
145+
elif settings.default_voice_code: # settings is next priority
146+
pipeline_lang_code = settings.default_voice_code
147+
else: # voice name is default/fallback
148+
pipeline_lang_code = voice_name[0].lower()
149+
144150
pipeline = self._get_pipeline(pipeline_lang_code)
145151

146152
logger.debug(
@@ -232,8 +238,8 @@ async def generate(
232238
await paths.save_voice_tensor(voice_tensor, temp_path)
233239
voice_path = temp_path
234240

235-
# Use provided lang_code or get from voice name
236-
pipeline_lang_code = lang_code if lang_code else voice_name[0].lower()
241+
# Use provided lang_code, settings voice code override, or first letter of voice name
242+
pipeline_lang_code = lang_code if lang_code else (settings.default_voice_code if settings.default_voice_code else voice_name[0].lower())
237243
pipeline = self._get_pipeline(pipeline_lang_code)
238244

239245
logger.debug(

‎docker/gpu/Dockerfile‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,50 @@ RUN apt-get update && apt-get install -y \
1212
libsndfile1 \
1313
curl \
1414
ffmpeg \
15+
g++ \
1516
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
1617
&& mkdir -p /usr/share/espeak-ng-data \
1718
&& ln -s /usr/lib/*/espeak-ng-data/* /usr/share/espeak-ng-data/
1819

1920
# Install UV using the installer script
2021
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
2122
mv /root/.local/bin/uv /usr/local/bin/ && \
22-
mv /root/.local/bin/uvx /usr/local/bin/ && \
23-
useradd -m -u 1000 appuser && \
24-
mkdir -p /app/api/src/models/v1_0 && \
25-
chown -R appuser:appuser /app
23+
mv /root/.local/bin/uvx /usr/local/bin/
2624

25+
# Create non-root user and set up directories and permissions
26+
RUN useradd -m -u 1000 appuser && \
27+
mkdir -p /app/api/src/models/v1_0 && \
28+
chown -R appuser:appuser /app
29+
2730
USER appuser
2831
WORKDIR /app
2932

3033
# Copy dependency files
3134
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
3235

36+
ENV PHONEMIZER_ESPEAK_PATH=/usr/bin \
37+
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
38+
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data
39+
3340
# Install dependencies with GPU extras (using cache mounts)
3441
RUN --mount=type=cache,target=/root/.cache/uv \
3542
uv venv && \
3643
uv sync --extra gpu
3744

38-
# Copy project files including models and sync again
45+
# Copy project files including models
3946
COPY --chown=appuser:appuser api ./api
4047
COPY --chown=appuser:appuser web ./web
4148
COPY --chown=appuser:appuser docker/scripts/ ./
4249
RUN chmod +x ./entrypoint.sh
43-
RUN --mount=type=cache,target=/root/.cache/uv \
44-
uv sync --extra gpu
50+
4551

4652
# Set all environment variables in one go
4753
ENV PYTHONUNBUFFERED=1 \
4854
PYTHONPATH=/app:/app/api \
4955
PATH="/app/.venv/bin:$PATH" \
5056
UV_LINK_MODE=copy \
51-
USE_GPU=true \
52-
PHONEMIZER_ESPEAK_PATH=/usr/bin \
53-
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
54-
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data
55-
57+
USE_GPU=true
58+
5659
ENV DOWNLOAD_MODEL=true
5760
# Download model if enabled
5861
RUN if [ "$DOWNLOAD_MODEL" = "true" ]; then \

0 commit comments

Comments
 (0)