pyttsx3 icon indicating copy to clipboard operation
pyttsx3 copied to clipboard

engine.save_to_file() produces empty file

Open angoodkind opened this issue 5 years ago • 15 comments

In running the code below, engine.say() works fine. However, when I save the audio to a file, the file is empty. I have also verified this in sox.

I am running pyttsx3 on a Macbook running OS 10.15.6.

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text") # successfully produced
engine.setProperty('volume',1.0)
volume = engine.getProperty('volume') 
print(volume)  # prints 1
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()
# engine.stop()

angoodkind avatar Sep 04 '20 21:09 angoodkind

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.91. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Sep 04 '20 21:09 issue-label-bot[bot]

Hi, Any updates on this? Thanks!

marek357 avatar Aug 26 '21 12:08 marek357

save_to_file seems to work in interactive mode but not in scripting mode.

$ python3
>>> import pyttsx3; engine = pyttsx3.init(); engine.save_to_file('Hello world', 'tmp.mp3'); engine.runAndWait();

Works as expected. But the following two ways don't work (they don't even create an empty file) (I am using Ubuntu 18.04).

$ python3 -c "import pyttsx3; engine = pyttsx3.init(); engine.save_to_file('Hello world', 'tmp.mp3'); engine.runAndWait();" 
$ python3 main.py 

where main.py is as follows:

import pyttsx3
engine = pyttsx3.init()
engine.save_to_file('Hello world', 'tmp.mp3')
engine.runAndWait()

Note that engine.say() is working (for me) in all three ways of invoking python.

Looking forward to any updates.

akkapakasaikiran avatar Dec 22 '21 09:12 akkapakasaikiran

Hello I have some issue with this code

import pyttsx3 engine = pyttsx3.init() engine.save_to_file('Hello World' , 'test.mp3') engine.runAndWait()

when I execute this Code. I get : AttributeError: 'Engine' object has no attribute 'save_to_file'

shakhrom96bs avatar Jan 10 '22 12:01 shakhrom96bs

can anyboda help me.

shakhrom96bs avatar Jan 10 '22 12:01 shakhrom96bs

y*

shakhrom96bs avatar Jan 10 '22 12:01 shakhrom96bs

I also got empty file when saving to ".mp3", but simply changing to ".aiff" resolved my issue.

According to Apple's documentation, NSSpeechSynthesizer synthesizes text into a sound (AIFF) file, so ".aiff" should be the supported format. (macOS 10.3+) https://developer.apple.com/documentation/appkit/nsspeechsynthesizer/1448394-startspeakingstring?language=objc

awesome-amy avatar Jan 14 '22 23:01 awesome-amy

what about windows? I did the same thing with windows and it just saved nothing

bqtd avatar May 11 '22 02:05 bqtd

me too,but in myself computer Normal operation ,Cloud computer make empty file,the cloud computer does not have a graphics card installed。Windows 10 system installed on cloud computer,can you help me.

MoYuFly avatar Aug 05 '22 06:08 MoYuFly

I also got empty file when saving to ".mp3", but simply changing to ".aiff" resolved my issue.

According to Apple's documentation, NSSpeechSynthesizer synthesizes text into a sound (AIFF) file, so ".aiff" should be the supported format. (macOS 10.3+) https://developer.apple.com/documentation/appkit/nsspeechsynthesizer/1448394-startspeakingstring?language=objc

That solved my problem! Thanks!

jgframoz avatar Sep 11 '22 20:09 jgframoz

For me (on macOS) it is able to create / save a .wav or .aiff file, but these are not readable / playable

gustavz avatar Jan 03 '23 15:01 gustavz

For me (on macOS) it is able to create / save a .wav or .aiff file, but these are not readable / playable

I have the same problem, did you manage to fix it?

Mateja9991 avatar Jan 05 '23 19:01 Mateja9991

For me (on macOS) it is able to create / save a .wav or .aiff file, but these are not readable / playable

The same problem with mac, works on windows tho. Did you solve it?

IlyaYakushevskiy avatar Jan 19 '23 11:01 IlyaYakushevskiy

This still produces empty files on mac, whether you use .wav, .mp3, or .aiff. Anyone know a way to fix this?

bearcatjamboree avatar Mar 02 '23 15:03 bearcatjamboree

I found a small hack to fix it https://github.com/nateshmbhat/pyttsx3/pull/267. Maybe someone can found better solution to fix it right 🥲

egorgam avatar Apr 01 '23 02:04 egorgam