Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use without file/Docker issues? #151

Open
JWBWork opened this issue Oct 17, 2020 · 9 comments
Open

Use without file/Docker issues? #151

JWBWork opened this issue Oct 17, 2020 · 9 comments

Comments

@JWBWork
Copy link

JWBWork commented Oct 17, 2020

I'm having an issue with pyttsx3 and Docker running linux. For some reason my code works locally but once I try to run it in docker I have an issue where save_to_file doesn't create a file, and doesn't throw an errror. I only get the following error once I try to read form the file.

FileNotFoundError: [Errno 2] No such file or directory: '/app/tmp/file_name.mp3'

Here is my dockerfile

FROM python:3.7.9

COPY . /app
WORKDIR /app

RUN apt-get update && apt-get upgrade -y
RUN apt-get install espeak -y
RUN apt-get install ffmpeg -y
RUN apt-get install libespeak1 -y
RUN python -m pip install -U -r requirements.txt

EXPOSE 5000

RUN mkdir -p /app/tmp
RUN chmod +rw /app/tmp
ENTRYPOINT ["python", "app.py"]

I'm trying to write audio files to tmp so that I can read the file, send the bytes to my frontend web app, and then delete the file.
I explicitly create the tmp directory and grant permissions to write in the Dockerfile, and I've tested reading and writing a file to that directly - it just seems to be a problem with pyttsx3 on linux in Docker.

Is there any solution to this?
Or, even better, is there some way pyttsx3 can give me a byte array in memory or as an object? It would be nice to have options other than having the script immediatly recite the text, or write it to a file. At least be able to pass a file like object to save_to_file so I can then read that file like object instead of actually writing to a file only to immediatly delete it.

@issue-label-bot
Copy link

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

@JWBWork
Copy link
Author

JWBWork commented Oct 18, 2020

Ok so it looks like this is the result of runAndWait not actually waiting.
When I ad this explicit check I can force the thread to wait until the file is created

while file_name not in os.listdir(tmp_path):
	socketio.sleep(1)

@Epicalert
Copy link

Ok so it looks like this is the result of runAndWait not actually waiting.
When I ad this explicit check I can force the thread to wait until the file is created

while file_name not in os.listdir(tmp_path):
	socketio.sleep(1)

Thanks, this workaround also fixes #149.

@jaredkeil
Copy link

Can anyone help find a similar fix without using socketio? Perhaps with the threading library? I'm not building a flask app. But having issues with engine.save_to_file() when giving a long string as the first arg. It appears pyttsx3 is cutting off after certain punctuation, as well as unpredictable reasons. On MacOS, using default driverName (nsss)

@TotallyAProgrammer
Copy link
Contributor

@jaredkeil You should probably open a new issue since your issue sounds different enough to warrant one.

@JWBWork
Copy link
Author

JWBWork commented Feb 4, 2021

@jaredkeil if it's the same issue I was having I think you could just implement the sleep function from the time module?

from time import sleep

while file_name not in os.listdir(tmp_path):
	sleep(1)

@jaredkeil
Copy link

jaredkeil commented Feb 9, 2021

@JWBWork Thanks for the reply. I'm a little unsure when to run engine.save_to_file() and engine.runAndWait() in relation to the above snippet? Before, during or after the while loop? Or is this an edit in the package itself?

@JWBWork
Copy link
Author

JWBWork commented Feb 9, 2021

@JWBWork Thanks for the reply. I'm a little unsure when to run engine.save_to_file() and engine.runAndWait() in relation to the above snippet? Before, during or after the while loop? Or is this an edit in the package itself?

I ran the loop with the sleep function after calling the function to save to a file. Basically it looks like on Linux it wasn't actually waiting, so the loop does the waiting.

@Sokkero
Copy link

Sokkero commented Sep 27, 2022

@JWBWork Hay, a little late to the thread but I encountered the same problem and also fixed it by simply using sleep(). Now that it is running I have the problem that the created files have terrible (truly awful) quality, barely even pronouncing any word.
Did you also struggle with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants