Skip to content

Instantly share code, notes, and snippets.

@willwade
Created July 26, 2024 14:40
Show Gist options
  • Save willwade/218ec9e356ae4c77b55ef282f051844d to your computer and use it in GitHub Desktop.
Save willwade/218ec9e356ae4c77b55ef282f051844d to your computer and use it in GitHub Desktop.
Test espeak with docker
# Use the official Python image as a base
FROM python:3.8-slim
# Set environment variables
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
# Install dependencies
RUN apt-get update && apt-get install -y \
espeak-ng \
git \
alsa-utils \
pulseaudio \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Create a working directory
WORKDIR /app
# Create the output directory
RUN mkdir -p /app/output
# Copy the requirements file into the container
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY . .
# Command to run the application
CMD ["python", "test_pyttsx3.py"]
git+https://github.com/willwade/py3-tts.git@master#egg=py3-tts
import pyttsx3
import os
def onStart(name):
print('starting', name)
def onWord(name, location, length):
print('word', name, location, length)
def onEnd(name, completed):
print('finishing', name, completed)
engine = pyttsx3.init('espeak')
engine.connect('started-utterance', onStart)
engine.connect('started-word', onWord)
engine.connect('finished-utterance', onEnd)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.save_to_file('Hello World', 'output/test.wav')
engine.runAndWait()
# Verify the file
output_file = 'output/test.wav'
if os.path.exists(output_file):
print(f"{output_file} exists")
if os.path.getsize(output_file) > 0:
print(f"{output_file} has data")
else:
print(f"{output_file} is empty")
else:
print(f"{output_file} does not exist")
@willwade
Copy link
Author

willwade commented Jul 26, 2024

docker build -t pyttsx3-app .
docker run --rm pyttsx3-app

or

docker run -it --rm -v ~/Desktop:/app/output pyttsx3-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment