nateshmbhat / pyttsx3

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
2.06k stars 326 forks source link

save_to_file silently fails when input is too long #259

Open MartinThoma opened 1 year ago

MartinThoma commented 1 year ago

I've noticed that save_to_file silently fails for slightly longer texts.

I guess that some people coming to https://github.com/nateshmbhat/pyttsx3/issues/7 / https://github.com/nateshmbhat/pyttsx3/issues/71 / https://stackoverflow.com/q/67625515/562769 might have the same issue.

Environment

Code

import sys
from pathlib import Path
import os

import pyttsx3 as tts   # pip install pyttsx3==2.90

engine = tts.init()

with open(sys.argv[1]) as fp:
    data = fp.read()

print(data)

# Say directly - more useful to me right now, but not so good for sharing
# the results on stack exchange
# engine.say(data)

# Store as a file so that I can share the result
out = str(Path('speech.mp3').resolve())
print(out)

print(engine.save_to_file(data, out))

engine.runAndWait()

Works

I went often to look at the collection of curiosities in Heidelberg Castle, and one day I surprised the keeper of it with my German. I spoke entirely in that language. He was greatly interested; and after I had talked a while he said my German was very rare, possibly a "unique"; and wanted to add it to his museum.

If he had known what it had cost me to acquire my art, he would also have known that it would break any collector to buy it.

Doesn't work

I went often to look at the collection of curiosities in Heidelberg Castle, and one day I surprised the keeper of it with my German. I spoke entirely in that language. He was greatly interested; and after I had talked a while he said my German was very rare, possibly a "unique"; and wanted to add it to his museum.

If he had known what it had cost me to acquire my art, he would also have known that it would break any collector to buy it. Harris and I had been hard at work on our German during several weeks at that time, and although we had made good progress, it had been accomplished under great difficulty and annoyance, for three of our teachers had died in the mean time.
jromerooo2 commented 1 year ago

In my case, it doesn't really generate anything unless I specify a format different from MP3 and the files seem to be broken...

jromerooo2 commented 1 year ago

If someone still needs it, I found gtts that has the function.save() that will accomplish the task correctly.

tylerq23 commented 1 year ago

Bump I have this same issue on Mac OS Ventura Python 3.11.2

jromerooo2 commented 1 year ago

@joemama0s Did you try using gTTS?