Created
July 26, 2024 14:40
-
-
Save willwade/218ec9e356ae4c77b55ef282f051844d to your computer and use it in GitHub Desktop.
Test espeak with docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git+https://github.com/willwade/py3-tts.git@master#egg=py3-tts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker build -t pyttsx3-app . docker run --rm pyttsx3-app
or