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

the method-save_to_file on Windows Server 2019 raise exception _ctypes.COMError: (-2147200966, None, (None, None, None, 0, None)) #260

Open
liudashang opened this issue Mar 9, 2023 · 3 comments
Assignees

Comments

@liudashang
Copy link

liudashang commented Mar 9, 2023

I'm writing a flask web which using the pyttsx3. the server's OS is win server 2019, it is a vmware virtualmachine. The virtualmachine does not have an audio card.
When I using RDP(mstsc) to connect the server, server 2019 will create a audio output device by “Remote audio playback”. I login the web by myself computer, and create a tts job. The program writing a wav file is OK.
But, when I disconnect the server, I create a tts job, the program writing a empty wav file. And the pyttsx3's debug info display:

Traceback (most recent call last):
  File "C:\Users\XXXXXX\AppData\Roaming\Python\Python39\site-packages\pyttsx3\driver.py", line 90, in _pump
    cmd[0](*cmd[1])
  File "C:\Users\XXXXXX\AppData\Roaming\Python\Python39\site-packages\pyttsx3\drivers\sapi5.py", line 69, in save_to_file
    temp_stream = self._tts.AudioOutputStream
_ctypes.COMError: (-2147200966, None, (None, None, None, 0, None))

The reason for this situation is, win server 2019 dose not have an audio output device, SpVoice AudioOutputStream Object will raise an exception.

My suggestion, change the source code pyttsx3\drivers\sapi5.py 'save_to_file'. add a 'try except' like this:

def save_to_file(self, text, filename):
    cwd = os.getcwd()
    stream = comtypes.client.CreateObject('SAPI.SPFileStream')
    stream.Open(filename, SpeechLib.SSFMCreateForWrite)
    try:
        temp_stream = self._tts.AudioOutputStream
        self._tts.AudioOutputStream = stream
        self._tts.Speak(fromUtf8(toUtf8(text)))
        self._tts.AudioOutputStream = temp_stream
    except:
        self._tts.AudioOutputStream = stream
        self._tts.Speak(fromUtf8(toUtf8(text)))
    stream.close()
    os.chdir(cwd)
@Jiangshan00001
Copy link

i have changed the code and commit to:https://github.com/Jiangshan00001/pyttsx4
you can have a try if you need:

pip install pyttsx4
import pyttsx4
engine = pyttsx4.init()
engine.save_to_file('Hello World' , 'test.wav')
engine.runAndWait()

@grydev
Copy link

grydev commented Apr 26, 2023

My suggestion, change the source code pyttsx3\drivers\sapi5.py 'save_to_file'. add a 'try except' like this

Adding the try except works perfect on a windows virtual machine - thank you!

@willwade
Copy link
Collaborator

Pretty sure we’ve fixed this. Will double check.

@willwade willwade self-assigned this Oct 17, 2024
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

4 participants