Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ docs/make.bat

# vscode
.vscode/

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/bin/python3"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ Feel free to wrap another text-to-speech engine for use with ``pyttsx3``.

### Project Links :

* PyPI (https://pypi.python.org)
* PyPI (https://pypi.org/project/pyttsx3/)
* GitHub (https://github.com/nateshmbhat/pyttsx3)
* Full Documentation (https://pyttsx3.readthedocs.org)
21 changes: 17 additions & 4 deletions example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""VOICE"""
voices = engine.getProperty('voices') #getting details of current voice

#engine.setProperty('voice', voices[0].id) #changing index, changes voices. 0 for male
engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female

Expand All @@ -28,7 +29,19 @@
engine.stop()


"""Saving Voice to a file"""
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()

"""To memory """
if sys.platform == 'win32':
# Windows-specific code
audio_array = []
engine.to_memory("Hello!", audio_array)
engine.to_memory("Hello again!", audio_array)
engine.runAndWait()
print(len(audio_array))
elif sys.platform == 'linux':
# Linux-specific code
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()
else:
print("Unsupported platform")

2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ clean:
rm -rf dist/
rm -rf build/
build:
pip3 install wheel
pip3 install wheel --user
python3 setup.py bdist_wheel
upload:
pip3 install twine
Expand Down
17 changes: 17 additions & 0 deletions pyttsx3/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ def save_to_file(self, text, filename, name):
@type name: str
'''
self._push(self._driver.save_to_file, (text, filename), name)

def to_memory(self, text, olist, name):
'''
Called by the engine to push a say command onto the queue.

@param text: Text to speak
@type text: unicode
@param name: Name to associate with this utterance. Included in
notifications about this utterance.
@param ostream: The opened output stream

>>> import pyttsx3
>>> engine = pyttsx3.init()
>>> ret = []
>>> engine.to_memory("hello", ret)
'''
self._push(self._driver.to_memory, (text, olist), name)

def getProperty(self, name):
'''
Expand Down
14 changes: 12 additions & 2 deletions pyttsx3/drivers/sapi5.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import os
import time
import weakref

from ctypes import c_int16
import pythoncom

from ..voice import Voice
from . import fromUtf8, toUtf8

Expand Down Expand Up @@ -80,6 +79,17 @@ def save_to_file(self, text, filename):
self._tts.AudioOutputStream = temp_stream
stream.close()
os.chdir(cwd)

def to_memory(self, text, olist):
stream = comtypes.client.CreateObject('SAPI.SpMemoryStream')
temp_stream = self._tts.AudioOutputStream
self._tts.AudioOutputStream = stream
self._tts.Speak(fromUtf8(toUtf8(text)))
self._tts.AudioOutputStream = temp_stream
data = stream.GetData()
olist.append([c_int16((data[i])|data[i+1]<<8).value for i in range(0,len(data),2)])
stream.close()


@staticmethod
def _toVoice(attr):
Expand Down
18 changes: 18 additions & 0 deletions pyttsx3/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,25 @@ def save_to_file(self, text, filename, name=None):
@type name: str
'''
self.proxy.save_to_file(text, filename, name)

def to_memory(self, text, olist, name=None):
'''
Adds an utterance to speak to the event queue.

@param text: Text to sepak
@type text: unicode
@param name: Name to associate with this utterance. Included in
notifications about this utterance.
@param ostream: The opened output stream

>>> import pyttsx3
>>> engine = pyttsx3.init()
>>> ret = []
>>> engine.to_memory("hello", ret)

'''
self.proxy.to_memory(text,olist, name)

def isBusy(self):
"""
@return: True if an utterance is currently being spoken, false if not
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


# Ubuntu: sudo apt install espeak ffmpeg

install_requires = [
'comtypes; platform_system == "Windows"',
'pypiwin32; platform_system == "Windows"',
Expand All @@ -11,6 +12,7 @@
]



with open('README.rst', 'r') as f:
long_description = f.read()

Expand Down