pyttsx3 icon indicating copy to clipboard operation
pyttsx3 copied to clipboard

save_to_file silently fails when input is too long

Open MartinThoma opened this issue 3 years ago • 4 comments

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

  • pyttsx3: Tried with latest on pip (2.90) and with current master ( https://github.com/nateshmbhat/pyttsx3/commit/5d3755b060a980f48fcaf81df018dd06cbd17a8f )
  • ffmpeg: 4.2.7-0ubuntu0.1
  • eSpeak text-to-speech: 1.48.03 04.Mar.14

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.

MartinThoma avatar Feb 21 '23 05:02 MartinThoma

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 avatar Mar 29 '23 00:03 jromerooo2

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

jromerooo2 avatar Apr 01 '23 18:04 jromerooo2

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

tylerq23 avatar Apr 12 '23 02:04 tylerq23

@joemama0s Did you try using gTTS?

jromerooo2 avatar Apr 12 '23 22:04 jromerooo2