Giter Site home page Giter Site logo

pyttsx's Introduction

pyttsx

Cross-platform Python wrapper for text-to-speech synthesis

Help Wanted

As you can probably tell, I have not had time or in some cases the resources (e.g., specific versions of OSes) to maintain pyttsx very well for some time now. If you are using pyttsx in your day to day work and would like to take over as maintainer of the project, please let me know.

Quickstart

import pyttsx
engine = pyttsx.init()
engine.say('Greetings!')
engine.say('How are you today?')
engine.runAndWait()

See http://pyttsx.readthedocs.org/ for documentation of the full API.

Included drivers

  • nsss - NSSpeechSynthesizer on Mac OS X 10.5 and higher
  • sapi5 - SAPI5 on Windows XP, Windows Vista, and (untested) Windows 7
  • espeak - eSpeak on any distro / platform that can host the shared library (e.g., Ubuntu / Fedora Linux)

Contributing drivers

Email the author if you have wrapped or are interested in wrapping another text-to-speech engine for use with pyttsx.

Project links

See Also

https://github.com/parente/espeakbox - espeak in a 16.5 MB Docker container with a simple REST API

License

Copyright (c) 2009, 2013 Peter Parente All rights reserved.

http://creativecommons.org/licenses/BSD/

pyttsx's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyttsx's Issues

Incomplete requirements on Mac

This is actually the same error mentioned here
http://stackoverflow.com/questions/12758591/python-text-to-speech-in-macintosh

From that issue, you see the following stack trace:

File "/Users/manabchetia/Documents/Codes/Speech.py", line 2, in <module>
    engine = pyttsx.init()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/__init__.py", line 39, in init
    eng = Engine(driverName, debug)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/engine.py", line 45, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/driver.py", line 64, in __init__
    self._module = __import__(name, globals(), locals(), [driverName])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/drivers/nsss.py", line 18, in <module>
ImportError: No module named Foundation

From some digging, it seems to depending on pyobjc under Mac OS X. However, I make no guarantee that is the only missing dependency...only the one we encountered when we were trying to make it work on Mac.

ImportErrror: No module named Foundation

-- I have read through all the other issues regarding this, I couldn't seem to find a solution.
My code:
`import pyttsx

engine = pyttsx.init()

engine.say("Hello")
engine.runAndWait()`
The error:
Traceback (most recent call last):
File "/Users/Elliot/Desktop/Python/speechEngineTest.py", line 3, in
engine = pyttsx.init()
File "/usr/local/lib/python2.7/site-packages/pyttsx/init.py", line 39, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python2.7/site-packages/pyttsx/engine.py", line 45, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/usr/local/lib/python2.7/site-packages/pyttsx/driver.py", line 64, in init
self._module = import(name, globals(), locals(), [driverName])
File "/usr/local/lib/python2.7/site-packages/pyttsx/drivers/nsss.py", line 18, in
from Foundation import *
ImportError: No module named Foundation

Any help regarding this issue would be appreciated. I love this module, and have used it before. After re-installing OS X, I get this error. Again, any help would be appreciated, many thanks.

Wrong language list in voices in espeak driver

In espeak, each voice has a list of associated languages with priorities. The espeak driver returns a single language with a leading control character such as "\c5en-us".

A fix request has been submitted.

Error "return -1" while using pyinstaller on a code which imports pyttsx

I have created a small project Which uses pyttsx. I want to distribute my code with no dependencies. So I used pyinstaller to create windows exe file. It has succesfully created a bundled exe file, but when I tried to execute that file it thrown error. I have googled for almost 6 hours but I didn't find any solution to my problem.

When I removed the lines which uses pyttsx the executable worked fine.

Here's the full description of Building and Running the file:

Build Details:

pyinstaller --onefile Full.py
39 INFO: PyInstaller: 3.2.dev0+e99e483
39 INFO: Python: 2.7.10
39 INFO: Platform: Windows-8-6.2.9200
42 INFO: wrote I:\Abhishek\Python\Weather Reporting\Weather Reporting 2\Full.spe
c
44 INFO: UPX is not available.
46 INFO: Extending PYTHONPATH with paths
['I:\\Abhishek\\Python\\Weather Reporting\\Weather Reporting 2',
 'I:\\Abhishek\\Python\\Weather Reporting\\Weather Reporting 2']
46 INFO: checking Analysis
46 INFO: Building Analysis because out00-Analysis.toc is non existent
46 INFO: Initializing module dependency graph...
49 INFO: Initializing module graph hooks...
88 INFO: running Analysis out00-Analysis.toc
90 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
  required by C:\Python27\python.exe
200 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.21022.8_none_18f8a87fd1919cd9.manifest
201 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
202 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
203 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.6871_none_acd48825e1d7842d.manifest
313 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.3
0729.6871_none ...
315 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1f
c8b3b9a1e18e3b_9.0.30729.6871_none_08e717a5a83adddf.manifest
316 INFO: Searching for file msvcr90.dll
317 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b
_9.0.30729.6871_none_08e717a5a83adddf\msvcr90.dll
317 INFO: Searching for file msvcp90.dll
319 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b
_9.0.30729.6871_none_08e717a5a83adddf\msvcp90.dll
319 INFO: Searching for file msvcm90.dll
320 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b
_9.0.30729.6871_none_08e717a5a83adddf\msvcm90.dll
428 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.21022.8_none_18f8a87fd1919cd9.manifest
430 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
431 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
432 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_
1fc8b3b9a1e18e3b_9.0.30729.6871_none_acd48825e1d7842d.manifest
434 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0,
30729, 6871)
498 INFO: Analyzing I:\Abhishek\Python\Weather Reporting\Weather Reporting 2\Ful
l.py
2250 INFO: Looking for import hooks ...
2256 INFO: Processing hook   hook-httplib.py
2257 INFO: Processing hook   hook-pyttsx.py
2327 INFO: Processing pre-safe import module hook   win32com
2951 INFO: Processing pre-find module path hook   distutils
3052 INFO: Processing hook   hook-pywintypes.py
3177 INFO: Processing hook   hook-encodings.py
3540 INFO: Processing hook   hook-win32com.py
3600 INFO: Processing hook   hook-pythoncom.py
3728 INFO: Processing hook   hook-distutils.py
3746 INFO: Looking for ctypes DLLs
3757 INFO: Analyzing run-time hooks ...
3769 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
3789 INFO: Looking for dynamic libraries
3996 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc
_1fc8b3b9a1e18e3b_9.0.21022.8_none_1179c2b5d66019bc.manifest
3997 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc
_1fc8b3b9a1e18e3b_9.0.30729.4148_none_a551ff35e6a96bed.manifest
4103 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.
30729.4148_none ...
4105 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.mfc_1
fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1.manifest
4106 INFO: Searching for file mfc90.dll
4106 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3
b_9.0.30729.4148_none_04480933ab2137b1\mfc90.dll
4106 INFO: Searching for file mfc90u.dll
4108 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3
b_9.0.30729.4148_none_04480933ab2137b1\mfc90u.dll
4108 INFO: Searching for file mfcm90.dll
4109 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3
b_9.0.30729.4148_none_04480933ab2137b1\mfcm90.dll
4109 INFO: Searching for file mfcm90u.dll
4111 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3
b_9.0.30729.4148_none_04480933ab2137b1\mfcm90u.dll
4217 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc
_1fc8b3b9a1e18e3b_9.0.21022.8_none_1179c2b5d66019bc.manifest
4217 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc
_1fc8b3b9a1e18e3b_9.0.30729.4148_none_a551ff35e6a96bed.manifest
4218 INFO: Adding redirect Microsoft.VC90.MFC version (9, 0, 21022, 8) -> (9, 0,
 30729, 4148)
4378 INFO: Looking for eggs
4379 INFO: Using Python library C:\Windows\system32\python27.dll
4379 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.MFC', language=None, arch=u'amd64', oldVe
rsion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 4148), publicKeyToken=u'1fc8b3b
9a1e18e3b'), BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'a
md64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 6871), publicKeyTok
en=u'1fc8b3b9a1e18e3b')]
4391 INFO: Warnings written to I:\Abhishek\Python\Weather Reporting\Weather Repo
rting 2\build\Full\warnFull.txt
4454 INFO: checking PYZ
4454 INFO: Building PYZ because out00-PYZ.toc is non existent
4455 INFO: Building PYZ (ZlibArchive) I:\Abhishek\Python\Weather Reporting\Weath
er Reporting 2\build\Full\out00-PYZ.pyz
4756 INFO: checking PKG
4756 INFO: Building PKG because out00-PKG.toc is non existent
4756 INFO: Building PKG (CArchive) out00-PKG.pkg
4828 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307
29, 6871)
8503 INFO: Bootloader C:\Python27\lib\site-packages\pyinstaller-3.2.dev0+e99e483
-py2.7.egg\PyInstaller\bootloader\Windows-64bit\run.exe
8503 INFO: checking EXE
8503 INFO: Building EXE because out00-EXE.toc is non existent
8504 INFO: Building EXE from out00-EXE.toc
8631 INFO: Appending archive to EXE I:\Abhishek\Python\Weather Reporting\Weather
 Reporting 2\dist\Full.exe
Run Details:

Traceback (most recent call last):
  File "<string>", line 155, in <module>
  File "site-packages\pyttsx\__init__.py", line 39, in init
  File "site-packages\pyttsx\engine.py", line 45, in __init__
  File "site-packages\pyttsx\driver.py", line 66, in __init__
  File "site-packages\pyttsx\drivers\sapi5.py", line 37, in buildDriver
  File "site-packages\pyttsx\drivers\sapi5.py", line 46, in __init__
  File "site-packages\win32com\client\__init__.py", line 309, in WithEvents
  File "site-packages\win32com\client\gencache.py", line 524, in EnsureModule
  File "site-packages\win32com\client\gencache.py", line 291, in MakeModuleForTy
pelib
  File "site-packages\win32com\client\makepy.py", line 286, in GenerateFromTypeL
ibSpec
  File "site-packages\win32com\client\gencache.py", line 554, in AddModuleToCach
e
  File "site-packages\win32com\client\gencache.py", line 633, in _GetModule
  File "c:\users\shubham\appdata\local\temp\tmpi0rbcs\gen_py\C866CA3A-32F7-11D2-
9602-00C04F8EE628x0x5x4.py", line 10, in <module>
    import win32com.client.CLSIDToClass, pythoncom, pywintypes
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 158, in load_module
    return self._importer.load_module(fullname, self._fullname)
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\pythoncom.py", line 2, in <module>
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 158, in load_module
    return self._importer.load_module(fullname, self._fullname)
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\win32\lib\pywintypes.py", line 2, in <module>
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 158, in load_module
    return self._importer.load_module(fullname, self._fullname)
  File "c:\python27\lib\site-packages\PyInstaller-3.2.dev0+e99e483-py2.7.egg\PyI
nstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "os.py", line 120, in <module>
ImportError: No module named path
Full returned -1

Here "Full" is the name of my script.

Any suggestions are invited.

I can't change the gender..., what i'm doing wrong?

Hi, first awesome lib! I'm using under linux and was preety easy to start, but now I want to change the speech to female... I'm trying with the code below without success... can you please help me?

import pyttsx

def say(text):
print "{}".format(text)
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
print voice.gender
engine.setProperty('female', voice.gender)
print "change: {}".format(voice.gender)
engine.say(text)
engine.runAndWait()

Thanks

Engine.isBusy() does not seem to return consistent value, according to documentation

As written in the title, isBusy() function does not return consistent value (at least on how I interpreted the documentation), namely True if the engine is currently busy speaking an utterance or False if not.

This can be checked when the engine is initialized, which obviously is not currently busy speaking, but still the function returns true.

The reason why this happen is that when the engine is initialized, the corresponding variable that saves whether the engine is busy or not is initialized to True.
Just initializing that value to False does not make the engine working correctly (i.e., using say() and runAndWait()). In the following I report what happens when _busy is initialized to False explaining why it does not work.
When say() is called, the command is pushed in the queue and _pump() is called, launching the command to start the utterance.
Then, when runAndWait() is called endLoop() is pushed in the command queue and "pumped" (according to _push() implementation) and then startLoop() is called. Note that when endLoop() is pushed in the command queue, variable _busy is False. So, as endLoop() is called, then the utterance is interrupted.

A possible solution is the following:
In driver.py (diff w.r.t. the current version on the repository (downloaded on July 20th, 2013) containing the modifications http://pastebin.com/mrvD6G4a):

  • Initialize the variable _busy to False
  • when pushing commands in the queue, do not pop them using _pump()
  • in endLoop() the last instruction should be setBusy(False) as the loop is ended and so there is no utterance spoken

In espeak.py (diff w.r.t. the current version on the repository (downloaded on July 20th, 2013) containing the modifications: http://pastebin.com/uin8ybPG; note that these modifications should be replicated in the other drivers):

  • in startLoop(), instead of setting _busy as False, call _pump to pop a command from the queue
  • in _onSynth, when utterance is terminated, we should _pump the endLoop command previously pushed in the queue, so that the loop is terminated.

The idea is that instead of setting variable _busy in an ad hoc way so that commands can be pumped, actually pump commands when they are actually processed.

This modification should correctly set the variable _busy (namely True if the engine is currently busy speaking an utterance or False if not), at least in the scenario I considered (i.e., call of say() and runAndWait()). For other scenarios (e.g., using externalLoop()), it should be carefully checked if the system still works.

Question on use of engine.iterate()

I am trying to use pyttsx to speak everything that comes out of the stdout of a process (currently on Mac, but on Windows too in future). Because I have to loop over the stdout of the process, I am trying to use pyttsx with my own event loop. I believe I have followed the example given in the docs, but the speech output stalls after the first message. I have added some print statements to the pyttsx code and found that the engine.iterate() call does not appear to reach the driver I am using (Mac).

I have put the TTS controller in a class and wrapped it so that the class can be used from a with statement, in order to ensure cleanup occurs.

class SpeakerManager(object):
    """Provide a context to for using Speaker in with statements."""
    def __enter__(self):    
        class Speaker(object):
            """Performs Text-To-Speech"""
            def __init__(self):
                self._engine = pyttsx.init()
                self._engine.startLoop(False)

            def say(self, message):
                sys.stdout.write("say: " + message)
                self._engine.say(message)
                self._engine.iterate()

            def cleanup(self):
                self._engine.endLoop()

        self.speaker = Speaker()
        return self.speaker

    def __exit__(self, type, value, traceback):
        self.speaker.cleanup()

This is how I am using the TTS, to speak everything that comes from the stdout of a process:

def launch(command_line):
    proc = subprocess.Popen(command_line, stdout=subprocess.PIPE)
    with SpeakerManager() as speaker:
        while True:
            retcode = proc.poll()
            line = proc.stdout.readline()
            speaker.say(line)
            if retcode is not None:
                break

I only get the first message spoken, but I get all of them printed out, prefixed with "say: " as per the code above.

I noted from the documentation something about the event loop needing manual management, but it seems that engine.iterate() is the cross-platform way to do this. Wondering what I'm doing wrong :-).

Thanks for writing this library; simple cross-platform TTS is just what I am looking for!

QUESTION: Python3 compatibility?

Is pyttsx compatible with Python3? That is, can I import it in a Python3 script? If not, do the developers hope to add Python3 capabilities?

Thanks!

pyttsx always busy

runAndWait infinitely loop. I think that's because of isBusy function which always returns "True".

ImportError: No module named Foundation

Hi Everybody, I have installed pyttsx but I can't get it to work. For some reason I need the module "Fondation" which I do not have. I'm using OS 10.10, and when I try to execute script using pyttsx functions I get the error below. I'm not sure what to do, any help would be greatly appreciated!

/Users/johanbjorck/.bashrc: line 1: p: command not found
Traceback (most recent call last):
File "/Users/johanbjorck/Google Drive/Sublime/earsight/pyttsx_test.py", line 3, in
engine = pyttsx.init()
File "/usr/local/lib/python2.7/site-packages/pyttsx/init.py", line 39, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python2.7/site-packages/pyttsx/engine.py", line 45, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/usr/local/lib/python2.7/site-packages/pyttsx/driver.py", line 64, in init
self._module = import(name, globals(), locals(), [driverName])
File "/usr/local/lib/python2.7/site-packages/pyttsx/drivers/nsss.py", line 18, in
from Foundation import *
ImportError: No module named Foundation
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/johanbjorck/Google Drive/Sublime/earsight/pyttsx_test.py"]
[dir: /Users/johanbjorck/Google Drive/Sublime/earsight]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

No module named pyttsx

Hi there,

I recently installed pyttsx via pip and am getting strange behavior.

This is the command I used to globally install pyttsx using pip:
sudo pip install pyttsx
Output:

The directory '/home/deusofnull/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/deusofnull/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/deusofnull/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyttsx
  Downloading pyttsx-1.1.tar.gz
Installing collected packages: pyttsx
  Running setup.py install for pyttsx
Successfully installed pyttsx-1.1

When I try to run my code, I am getting this error:

deusofnull@deusofnull:~/codes/random_words$ python rando-words.py 
Traceback (most recent call last):
  File "rando-words.py", line 2, in <module>
    import pyttsx
ImportError: No module named pyttsx

I'm confused because when I try to upgrade pyttsx, I get verification that it is installed and up to date:

deusofnull@deusofnull:~/codes/random_words$ pip install pyttsx --upgrade
Requirement already up-to-date: pyttsx in /usr/local/lib/python3.4/dist-packages

Is this a pip permissions issue? What is the best way to safely install pyttsx globally on Ubuntu 14.04?

Thanks!

Segfault on Ubuntu 10.10, 11.04

Situation:

import pyttsx
pyttsx.init()
Segmentation fault

Cause:
In pyttsx/drivers/espeak.py, in init(), self.getProperty('voice') results in a call to GetCurrentVoice() in _espeak.py, which calls espeak_GetCurrentVoice() in libespeak.so.1. libespeak is returning a valid result with an empty name. EspeakDriver._defaultVoice gets set to None. A subsequent call to self.setProperty() references the None value, and causes a segmentation fault.

Possible solution:
I know nothing of espeak or its API. Mine works, but does not return a 'current voice'. This solved the problem on my machine:

Replace line 37 of espeak.py:

EspeakDriver._defaultVoice = self.getProperty('voice')

With this block:

EspeakDriver._defaultVoice = self.getProperty('voice')
if EspeakDriver._defaultVoice == None:
    EspeakDriver._defaultVoice = "en"

This just defaults to english if espeak doesn't return a voice. Text-to-speech works as expected after this modification.

Version information:
Ubuntu Server 10.10
Python 2.7
pyttsx-1.0
libespeak1 version 1.44.05~really-1.44.04-0ubuntu1

Not an issue, but a question. Ending a pyttsx thread

in my python program I am starting a thread. This thread creates a engine object and invokes engine.runAndWait() . engine.stop() (inside onWord()) is called to stop the engine and end the thread. After this another identical thread using the same function is created . Now the problem starts. even though the first thread is dead. something still interferes with the second thread and does not allow it to work properly.

Basically what I want to do is stop a previous pyttsx instance and start another pyttsx instance. All this effort is directed at having something like a pause feature...

Here is the full code of my tiny 'program' : http://pastebin.com/dnCd3KjS

Hope I was able to make myself clear.

Segfault on Linux

import pyttsx
engine = pyttsx.init()
[New Thread 0x7fffefb4a700 (LWP 2817)]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75af9fc in ?? () from /lib/libc.so.6
(gdb) bt
#0 0x00007ffff75af9fc in ?? () from /lib/libc.so.6
#1 0x00007fffefb5787c in ?? () from /usr/lib/libespeak.so.1
#2 0x00007fffefb7428d in ?? () from /usr/lib/libespeak.so.1
#3 0x00007ffff01b6ee8 in ffi_call_unix64 () from /usr/lib/libffi.so.6
#4 0x00007ffff01b6c84 in ffi_call () from /usr/lib/libffi.so.6
#5 0x00007ffff03caa0c in _CallProc () from /usr/lib64/python2.6/lib-dynload/_ctypes.so
#6 0x00007ffff03c3e28 in ?? () from /usr/lib64/python2.6/lib-dynload/_ctypes.so
#7 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#8 0x00007ffff7b144cc in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#9 0x00007ffff7b15efe in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#10 0x00007ffff7b168d7 in PyEval_EvalCodeEx () from /usr/lib/libpython2.6.so.1.0
#11 0x00007ffff7aa9e30 in ?? () from /usr/lib/libpython2.6.so.1.0
#12 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#13 0x00007ffff7a94b8d in ?? () from /usr/lib/libpython2.6.so.1.0
#14 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#15 0x00007ffff7ad449e in ?? () from /usr/lib/libpython2.6.so.1.0
#16 0x00007ffff7ad30d8 in ?? () from /usr/lib/libpython2.6.so.1.0
#17 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#18 0x00007ffff7b144cc in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#19 0x00007ffff7b15efe in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#20 0x00007ffff7b168d7 in PyEval_EvalCodeEx () from /usr/lib/libpython2.6.so.1.0
#21 0x00007ffff7aa9e30 in ?? () from /usr/lib/libpython2.6.so.1.0
#22 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#23 0x00007ffff7a94b8d in ?? () from /usr/lib/libpython2.6.so.1.0
#24 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#25 0x00007ffff7ad449e in ?? () from /usr/lib/libpython2.6.so.1.0
#26 0x00007ffff7ad30d8 in ?? () from /usr/lib/libpython2.6.so.1.0
#27 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#28 0x00007ffff7b144cc in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#29 0x00007ffff7b168d7 in PyEval_EvalCodeEx () from /usr/lib/libpython2.6.so.1.0
#30 0x00007ffff7aa9e30 in ?? () from /usr/lib/libpython2.6.so.1.0
#31 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#32 0x00007ffff7a94b8d in ?? () from /usr/lib/libpython2.6.so.1.0
#33 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#34 0x00007ffff7ad449e in ?? () from /usr/lib/libpython2.6.so.1.0
#35 0x00007ffff7ad30d8 in ?? () from /usr/lib/libpython2.6.so.1.0
#36 0x00007ffff7a82102 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#37 0x00007ffff7b144cc in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#38 0x00007ffff7b168d7 in PyEval_EvalCodeEx () from /usr/lib/libpython2.6.so.1.0
#39 0x00007ffff7b14ca1 in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#40 0x00007ffff7b168d7 in PyEval_EvalCodeEx () from /usr/lib/libpython2.6.so.1.0
#41 0x00007ffff7b169b2 in PyEval_EvalCode () from /usr/lib/libpython2.6.so.1.0
#42 0x00007ffff7b30cdc in ?? () from /usr/lib/libpython2.6.so.1.0
#43 0x00007ffff7b3277c in PyRun_InteractiveOneFlags () from /usr/lib/libpython2.6.so.1.0
#44 0x00007ffff7b3298e in PyRun_InteractiveLoopFlags () from /usr/lib/libpython2.6.so.1.0
#45 0x00007ffff7b32a9c in PyRun_AnyFileExFlags () from /usr/lib/libpython2.6.so.1.0
#46 0x00007ffff7b3e2fc in Py_Main () from /usr/lib/libpython2.6.so.1.0
#47 0x00007ffff74b6f0d in __libc_start_main () from /lib/libc.so.6
#48 0x00000000004008c9 in _start ()

the system keeps on speaking.

I am new to python. Your solution almost fixed my problem. But there is another issue. After i applied your fix my system continuously goes on speaking in different manner; like french, german etc.! I have no idea why. It sounds strange but i want it to speak english only.
I am running a virtual machine of Fedora 20 python 2.7. Please help.

No module named 'engine'

Traceback (most recent call last):
  File "stests.py", line 35, in <module>
    import pyttsx
  File "/usr/local/lib/python3.6/site-packages/pyttsx/__init__.py", line 18, in <module>
    from engine import Engine
ModuleNotFoundError: No module named 'engine'

What is this error?

Microsoft Speech Platform

Hi,
I've discovered that the Microsoft Speech Platform (http://www.microsoft.com/en-au/download/details.aspx?id=27225) shares the same COM interface as the Speech API (SAPI) that comes with windows.

I've been able to use the vastly superior Speech Platform voices from here with pyttsx:
http://www.microsoft.com/en-us/download/details.aspx?id=27224

All I had to do was change the SAPI COM object from:
self._tts = win32com.client.Dispatch('SAPI.SPVoice')

to:
self._tts = win32com.client.Dispatch('{d941651c-44e6-4c17-badf-c36826fc3424}')

As far as I can tell there isn't a nice name for the Speech Platform COM object but it does work.

Is there any language with female gender?

import pyttsx
engine = pyttsx.init()
voices = engine.getProperty('voices')
male_language_count = 0
female_language_count = 0
none_language_count = 0
for voice in voices:
    if voice.gender == 'male':
    	# female language count
        male_language_count += 1
    elif voice.gender == 'female':
    	# female language count
		female_language_count +=1
	else:
        # None language count
        none_language_count += 1

print 'Male gender language count : %d' %  male_language_count
print 'Female gender language count : %d' % female_language_count
print 'None gender language count : %d' % none_language_count

Output

Male gender language count : 60
Female gender language count : 0
None gender language count : 9

How i change the english and spanish language gender to female?

how to change the voice and age?

how to change the voice or how to install a new voice?And i also wonder that can i change the age Property?Thanks in advance.

Strange behaviour of the engine when stop() was called

The following test script was executed under Windows 7 and Ubuntu 12.04 and documents some strange behaviour of the onStop() function. The code was taken from the documentation example "Interrupting an utterance" and a second sentence was added to be read out.

The test script:

import os
import sys
sys.path.insert(0, os.path.join('..', '..'))
import pyttsx
import time

def onWord(name, location, length):
   print 'word', name, location, length
   if location > 10:
      engine.stop()

engine = pyttsx.init()
engine.connect('started-word', onWord)

engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

print("")
time.sleep(2)

engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

Output under Windows 7:

$ python interrupting.py
word None 0 3
word None 4 5
word None 10 5
word None 16 3
word None 20 6

word None 0 3
word None 4 5
word None 10 5
word None 16 3
word None 20 6
word None 27 4
word None 32 3
word None 36 4
word None 41 3

Output under Ubuntu:

$ python interrupting.py
word None 0 3
word None 4 5
word None 10 5
word None 16 3

word None 0 3
word None 4 5
word None 10 5
word None 16 3
word None 20 6
word None 27 4
word None 32 3
word None 36 4
word None 41 3

You can see that stopping the utterance in the example code works for the first execution of runAndWait() (more or less, since it should be stopped after the fourth word which it doesn't under Windows, but this might be some asynchronous timing issue), but not for the second.

The second utterance with the exact same engine does not stop as requested but continues to read out all the text. This happens for both operating systems.

Another thing is, that under Ubuntu the given script crashes randomly after stop() was called. Sometimes even before the second utterance is started, sometimes during the second one. However, sometimes it is executed correctly and does not crash. Since this only happens under Linux this seems to be an issue with the espeak.py driver (my espeak version is 1.46.02).

I can save the output of pyttsx to a wav file in windows, but the process suspended

sorry for I just have a little knowledge about both Python and win32 API.

but I had tried the old PYTTS package and some other code from google, and finnaly can save the wav file, by editing the pyttsx/drivers/sapi5.py as the following:

insert a line self._stream = win32com.client.Dispatch('SAPI.SpFileStream') after self._tts = win32com.client.Dispatch('SAPI.SPVoice') to create a file stream .

and in the function say , add some code around self._tts.Speak(unicode(text), 19) :

self._stream.Open("test.wav", 3) 
self._tts.AudioOutputStream = self._stream
self._tts.Speak(unicode(text), 19)

it worked, but, my python script never stopped, just suspended, I had try to edit the say function and runAndWait function, failed with my poor knowledge,

maybe somebody can help me?
or maybe some other way to record the tts 's output to wav or mp3 files---I tried to record by pyaudio, but it always recorded the microphone directly.

Phrase not spoken on second call to runAndWait()

Hey there! So I installed your library from pip and started playing around with it. There's a weird bug I'm encountering on Ubuntu 15.04 with Python 2.7.9. When I run this for the first time:

   engine.say('The quick brown fox jumped over the lazy dog.')
   engine.runAndWait()

it works correctly, but when I run the exact same code again in a program the voice cuts off after saying the beginning of the phrase (I'd say one or two characters in). I noticed this running your Changing voices example.

Mac OSX Sierra

So, I'm using the "Speaking Text" example from:
http://pyttsx.readthedocs.io/en/latest/engine.html#the-engine-factory

"import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()"

But IDLE keeps giving me the following error:
"Traceback (most recent call last):
File "/Users/Tuck/Desktop/Untitled.py", line 2, in
engine = pyttsx.init()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/init.py", line 39, in init
eng = Engine(driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/engine.py", line 45, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/driver.py", line 64, in init
self._module = import(name, globals(), locals(), [driverName])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/drivers/nsss.py", line 18, in
from Foundation import *
ImportError: No module named Foundation"

What's going on? How can I fix this...? Thoughts?

Windows 7 Unit Test fail

As requested in #10 I installed and tested pyttsx on a Windows 7 64-bit machine with the following results of a full unit test run.

I used python 2.7.5 with pywin32-218 and no additional TTS software installed. As you can see from the command line output the testStop() fails.

$ python27 test_all.py
testReuseDriver (test_lifecycle.TestLifecycle) ... ok
testSeparateDrivers (test_lifecycle.TestLifecycle) ... ok
testBadRate (test_prop.TestProperties) ... ok
testBadVoice (test_prop.TestProperties) ... ok
testBadVolume (test_prop.TestProperties) ... ok
testDefaults (test_prop.TestProperties) ... ok
testSetMultiple (test_prop.TestProperties) ... ok
testSetRate (test_prop.TestProperties) ... ok
testSetVoice (test_prop.TestProperties) ... ok
testSetVolume (test_prop.TestProperties) ... ok
testExternalLoop (test_say.TestSay) ... ok
testMultipleRuns (test_say.TestSay) ... ok
testMultipleSay (test_say.TestSay) ... ok
testMultipleStopBeforeSay (test_say.TestSay) ... ok
testSay (test_say.TestSay) ... ok
testSayTypes (test_say.TestSay) ... ok
testStartEndLoop (test_say.TestSay) ... ok
testStop (test_say.TestSay) ... pythoncom error: Python error invoking COM method.

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 277, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 282, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_
    return func(*args)
  File "..\..\pyttsx\drivers\sapi5.py", line 148, in OnEndStream
    if d._speaking:
ReferenceError: weakly-referenced object no longer exists
FAIL
testStopBeforeSay (test_say.TestSay) ... pythoncom error: Python error invoking COM method.

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 277, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 282, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Program Files (x86)\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_
    return func(*args)
  File "..\..\pyttsx\drivers\sapi5.py", line 148, in OnEndStream
    if d._speaking:
ReferenceError: weakly-referenced object no longer exists
ok

======================================================================
FAIL: testStop (test_say.TestSay)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\mstein\development\pyttsx\tests\unit\test_say.py", line 113, in testStop
    self.assert_(len(self.events) < len(self.correct[0]))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 19 tests in 30.065s

FAILED (failures=1)

Interestingly stop() seems to work properly (under Windows 7, but see #16), at least when used as shown in the "Interrupting an utterance" example from the docs. Apart from that, most of pyttsx seems to work for Windows 7 like for Ubuntu. This means that the following calls work like expected/documented:

  • init()
  • connect() and disconnect()
  • getProperty() and setProperty()
  • startLoop() and endLoop()
  • say()
  • runAndWait()

For the "correctness" of isBusy() see #13, for issues with stop() see #16.

Callback gets confused over word-boundaries.

[Tested only on Windows. Low severity.]

A call to say with non-words, such as:

say('/////')
say('/?.!@")

will, quite reasonably, result in the engine pronouncing each of the punctuation characters separately rather than as a word.

For each of the punctuation characters, the started-word callback is called - again this is reasonable.

However, the location and length parameters do not indicate the individual character being pronounced, but the whole non-word.

That is, the callback is called repeatedly, once for every letter, with exactly the same parameters.

I would expect either: the callback is only made once, for the whole non-word, or that the callback is made for each character, with a location than increments by one each time, and a length of 1.

Note: I haven't eliminated that this might be a bug in SAPI rather than pyttsx.

pyttsx fails to install on Windows 10

I have installed both 32 and 64 bit versions of 220 from:
https://sourceforge.net/projects/pywin32/files/pywin32/

However to no avail.

{lamb} pip install git+https://github.com/parente/pyttsx.git
Collecting git+https://github.com/parente/pyttsx.git
  Cloning https://github.com/parente/pyttsx.git to c:\users\jan\appdata\local\temp\pip-yjrai1-build
Collecting win32com (from pyttsx==1.2)
  Could not find a version that satisfies the requirement win32com (from pyttsx==1.2) (from versions: )
No matching distribution found for win32com (from pyttsx==1.2)
You are using pip version 7.1.2, however version 8.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Anyone experiencing the same issue?

C:\Users\jan {git}
{lamb} python
Python 2.7.11 |Anaconda 2.3.0 (64-bit)| (default, Dec  7 2015, 14:10:42) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import win32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named win32
>>> import win32com
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jan\Anaconda\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.
>>>

Voice change male to female

Hello I am newbie for this module . I want to change the voice male to female but I can't please check my code and late me know .
import pyttsx engine = pyttsx.init() voices = engine.getProperty('voices') rate = engine.getProperty('rate') for voice in voices: print(voice.gender) engine.setProperty('voice', voice.id) engine.say("This is testing")
I checked my terminal . I saw all voices are male , there is no female voice .. and also suggest me if I can add custom voice . Thanks

engine.runAndWait() hangs on OS X Yosemite

Using the function engine.runAndWait() hangs and never returns, all of the callbacks work just fine but engine.runAndWait() never returns. This effects OS X Yosemite but not OS X Mavericks.

Threading problems with OS X

PyTTSX does not seem to work in a python thread in OS X. The exact failure depends on whether PyGTK is also in use.

I am initializing a pyttsx engine:
engine = pyttsx.Engine()

And trying to speak in an infinite loop:

    while True:
        text = "Say something, say something, anything."
        engine.say(text)
        engine.runAndWait()

I have tried this with and without PyGTK, and both in its own thread and in the main python thread. I have encountered a number of different results.

A demo is available here: https://gist.github.com/1447666

In second thread, no GTK

Setup:
I do NOT import gtk or gobject. I execute the above code in a thread using Python's threading.Thread() class.

Execution result:
The text is spoken one time, and then the program hangs.

Trace results:
The queue in pyttsx's driver.py "pumps" one time, gets the text out, and speaks it. The queue never "pumps" again, so the self._engine.endLoop() function never runs. The thread hangs forever.

In second thread, with GTK

Setup:
I import gtk and gobject, run gobject.threads_init(), and run gtk.main(). The above code is run in a thread.

Execution result:
The text is spoken once, and then the program exits.

Trace result:
PyTTSX's nsss.py driver calls AppHelper.runConsoleEventLoop(). When the speech is complete, self._engine.endLoop() IS removed from the queue and executes, which calls AppHelper.stopEventLoop(). In PyObjC's AppHelper, stopEventLoop() gets None for PyObjCAppHelperRunLoopStopper.currentRunLoopStopper(), and it responds by calling NSApp()._terminate(), which kills the entire application and all threads.

In main thread, with GTK

Setup:
I import gtk and gobject. I do NOT run gtk.main(). The above code is run in the main thread, no secondary thread is started.

Execution result:
The text is spoken once, and then the program exits.

Trace results:
I did not trace this case, but I can tell it is different from the others (I have print statements all throughout my pyttsx and pyobjc modules -- this case takes a different path). Notably, it does not hang forever (endLoop() is called and the queue is empty), and it is not terminated by stopEventLoop().

NSSpeechDriver: 'super' object has no attribute 'init'

Hi All !
I grab this code from the examples:

import pyttsx
engine = pyttsx.init()
engine.say('How are you today?')
engine.runAndWait()

but is failing with a:

Traceback (most recent call last):
  File "run.py", line 2, in <module>
    engine = pyttsx.init()
  File ".../venv/lib/python2.7/site-packages/pyttsx/__init__.py", line 39, in init
    eng = Engine(driverName, debug)
  File ".../venv/lib/python2.7/site-packages/pyttsx/engine.py", line 45, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File ".../venv/lib/python2.7/site-packages/pyttsx/driver.py", line 66, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File ".../venv/lib/python2.7/site-packages/pyttsx/drivers/nsss.py", line 24, in buildDriver
    return NSSpeechDriver.alloc().initWithProxy(proxy)
  File ".../venv/lib/python2.7/site-packages/pyttsx/drivers/nsss.py", line 28, in initWithProxy
    self = super(NSSpeechDriver, self).init()
AttributeError: 'super' object has no attribute 'init'

Running it on:

OSX Yosemite 10.10.3
Python 2.7.6
pyobjc==3.0.4
pyobjc-core==3.0.4
pyttsx==1.1

Any thoughts ? Any help will be really appreciated !

pyttsx.init('epseak').say doesn't work the second time

engine.say just work for the first time, however all the next call to 'speak' it just say the first letter.
I also tried not using functions but nothing changed, am i doing something wrong?

import pyttsx
import os

engine = pyttsx.init('espeak')
engine.setProperty('rate', 150)

def speak(text):
     engine.say(text)
     engine.runAndWait()

speak("executing command...")
os.system("echo test")
speak("command executed")

Mac VoiceLanguage is now VoiceLocaleIdentifier

pyttsx 1.0 was working fine for me on a Mac running Lion. Then I added some new I18n voices (via the Dictation & Speech) control panel, and pyttsx started crashing on the getProperty('voices') call, making it essentially unusable. Version 1.1 of pyttsx has the same bug.

I traced the error to line 70 of drivers/nsss.py, where it has attr['VoiceLanguage'], which is now deprecated. Changing this to attr['VoiceLocaleIdentifier'] fixed the problem. It appears VoiceLanguage was deprecated in OSX10.5, and now has actually ceased to exist for some voices.

I got a error about the win32api in windows xp

Traceback (most recent call last):
File "F:\test.py", line 2, in
engine = pyttsx.init()
File "D:\Program\Python27\lib\site-packages\pyttsx__init__.py", line 39, in i
nit
eng = Engine(driverName, debug)
File "D:\Program\Python27\lib\site-packages\pyttsx\engine.py", line 45, in i
nit

self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "D:\Program\Python27\lib\site-packages\pyttsx\driver.py", line 64, in i
nit

self.module = import(name, globals(), locals(), [driverName])
File "D:\Program\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 19,
in
import win32com.client
File "D:\Program\Python27\lib\site-packages\win32com__init
_.py", line 5, in

import win32api, sys, os
ImportError: DLL load failed: Can not find the specified module

I am using python 2.7.5

F:>pip list
beautifulsoup4 (4.2.1)
Django (1.5.1)
docutils (0.11)
feedparser (5.1.3)
ipython (1.0.0)
Jinja2 (2.7)
MarkupSafe (0.18)
MySQL-python (1.2.4b4)
numpy (1.7.1)
pdfrw (0.1)
PIL (1.1.7)
poster (0.8.1)
py2exe (0.6.9)
pyFirmata (0.9.5)
Pygments (1.6)
pyHook (1.5.1)
pyserial (2.6)
pyttsx (1.1)
pywin32 (218)
reportlab (2.7)
rst2pdf (0.93.dev)
Sphinx (1.2b1)
wx (1.0.0)

runAndWait() doesn't return when calling say(..) with umlauts

engine = pyttsx.init()
engine.say("Bächtig möse")
engine.runAndWait() # <--- This call won't return

Hi, was just wondering why my program doesn't continue. Of course, quick fix is to just replace such characters before calling say(..). Don't know if there are other characters causing that behavior.
Tested with python 2.7 under Windows 7

Support cross platform save to disk

Feature requested numerous times now. Look into the feasibility of doing this cross platform via a consistent API. Use contributed code when possible. To maintain the mantra of "crossplatform TTS", only deliver if possible to do via a single API using all three included drivers.

Document maintainer workflow

@nickgermaine has graciously stepped up to take over as the prime maintainer of the project. I need to at least provide some documentation about how to run tests, build docs, cut releases, etc. to get him started. This is my reminder to do so.

Nick, if you hit any problems in the meantime, leave comments here.

Save output to file

Hi,

I would be very interesting if instead of playing the sound I could also use the library to save it to a file.
At the moment I have to use system call to do this and using pyttsx for this would be nice.

I wish I could provide a patch but this is beyond my python skills.

'super' object has no attribute 'init'

speech_engine = pyttsx.init() in Mac OS X renders the following error:

`AttributeError Traceback (most recent call last)
in ()
----> 1 speech_engine = pyttsx.init()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/init.pyc in init(driverName, debug)
37 eng = _activeEngines[driverName]
38 except KeyError:
---> 39 eng = Engine(driverName, debug)
40 _activeEngines[driverName] = eng
41 return eng

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/engine.pyc in init(self, driverName, debug)
43 @type debug: bool
44 '''
---> 45 self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
46 # initialize other vars
47 self._connects = {}

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/driver.pyc in init(self, engine, driverName, debug)
64 self._module = import(name, globals(), locals(), [driverName])
65 # build driver instance
---> 66 self._driver = self._module.buildDriver(weakref.proxy(self))
67 # initialize refs
68 self._engine = engine

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/drivers/nsss.pyc in buildDriver(proxy)
22
23 def buildDriver(proxy):
---> 24 return NSSpeechDriver.alloc().initWithProxy(proxy)
25
26 class NSSpeechDriver(NSObject):

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx/drivers/nsss.pyc in initWithProxy(self, proxy)
26 class NSSpeechDriver(NSObject):
27 def initWithProxy(self, proxy):
---> 28 self = super(NSSpeechDriver, self).init()
29 if self:
30 self._proxy = proxy

AttributeError: 'super' object has no attribute 'init'`

Can seek some help please?

Speech stops halfway while speaking

Hi @parente,

I am using Ubuntu 16.01 LTS, I am facing problem with the speech, here is my sample code

import pyttsx

engine = pyttsx.init('espeak')
engine.say('Hello, I am C 4 3 2 1, What can I do for you ?')
engine.say('A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z')
engine.runAndWait()

When I try to execute the above code, it speaks first line clearly but it fails to speak second line. In some scenarios it doesn't speak even first line clearly.

Can you please advise, thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.