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

eSpeak support #6

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

eSpeak support #6

wants to merge 24 commits into from

Conversation

willwade
Copy link

@willwade willwade commented Jun 17, 2024

eSpeak does have one remaining issue. WordEvents are emitted but they occur BEFORE the words are spoken aloud. (fixed here)

Please check my code. I've had a lot of debug code in my work which I think I have stripped out

@willwade
Copy link
Author

willwade commented Jul 7, 2024

anyone out there had a chance to test this?!

@DGrothe-PhD
Copy link

Okay, but I need helping.
Steps:

  1. Clone your repo to a local folder on my machine
  2. What's next? Do I have to compile anything? Adapt any internal path? Install code through special pip install prompt for local resources?

I guess I should uninstall existing py3-tts or even better try and run this from another machine?!

@willwade
Copy link
Author

willwade commented Jul 8, 2024

  1. Install eSpeak-ng https://github.com/espeak-ng/espeak-ng/blob/master/docs/guide.md#installation . if on a Mac just note the homebrew build out there isnt working on Apple Silicon - so you may need to install from source (its painless!) https://github.com/espeak-ng/espeak-ng/blob/master/docs/building.md

UPDATE: IF ANYONE IS FOLLOWING AT HOME SEE MY UPDATED COMMENT BELOW!!

  1. Copy the below code into a file. lets call it test.py
import pyttsx3
engine = pyttsx3.init('espeak')
voices = engine.getProperty('voices')
for voice in voices:
   engine.setProperty('voice', voice.id)
   engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

Now in usual py3-tts does this work? In my experience at least it didnt. So now lets try my PR

gh repo clone thevickypedia/py3-tts
cd py3-tts
git fetch origin pull/6/head:MASTER

(or using your GitHub desktop app and getting the pull request 6)

then try it out. You shouldnt have to uninstall py3-tts but if you want you can. the key is this

cd py3-tts
pip install -e .

now in the same shell session try our test.py

If test.py works you can try other things like event loops eg

import pyttsx3
def onStart(name):
   print 'starting', name
def onWord(name, location, length):
   print 'word', name, location, length
def onEnd(name, completed):
   print 'finishing', name, completed
engine = pyttsx3.init('espeak')
engine.connect('started-utterance', onStart)
engine.connect('started-word', onWord)
engine.connect('finished-utterance', onEnd)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

What it should do? Work! Previously it just wouldnt sound out anything or complain about no dll/so file..

@DGrothe-PhD
Copy link

DGrothe-PhD commented Jul 9, 2024

Hi,
I've just tested it on my Windows 11 Pro; well it does not work:
I could do and observe everyting as you wrote but when I tried
"now in the same shell session try our test.py.".
I got some kind of "frozen bootstrap" message. Restarted my laptop (just in case an environment variable was missing after freshly installed eSpeak) and got the same message. See attached file pyttsx3_init_eSpeak.txt.

In the files I attached, ~\py3-tts is just the abbreviation of the path to where gh repo clone did it.
↠ What puzzles me is that even trying pyttsx3 locally, when I do SpeakerStatus.engine = pyttsx3.init(),
it still rings back to Python's installation folder (or just seems to tell me so) as I still get, see file pyttsx3_init_default.txt
PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\Python311\\Lib\\site-packages\\comtypes\\gen\\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py'

So that at least makes me think that import pyttsx3 does not always import everything from the PR instead of ringing back to my installation folder(s).

pyttsx3_init_eSpeak.txt

File 2.
pyttsx3_init_default.txt

Chances are that I can get this working on an older laptop where I suppose I didn't install any pyttsx3 yet so that on an empty ground it doesn't get confused.

@willwade
Copy link
Author

willwade commented Jul 10, 2024

My bad. try this

Install eSpeak-ng https://github.com/espeak-ng/espeak-ng/blob/master/docs/guide.md#installation . if on a Mac just note the homebrew build out there isnt working on Apple Silicon - so you may need to install from source (its painless!) https://github.com/espeak-ng/espeak-ng/blob/master/docs/building.md (Same as last time)

Now use virtualenv

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

now pip install from my repo (this PR)

pip install git+https://github.com/willwade/py3-tts.git@master#egg=py3-tts

Save the below to a file eg test_pyttsx3.py

import pyttsx3

def onStart(name):
    print('starting', name)

def onWord(name, location, length):
    print('word', name, location, length)

def onEnd(name, completed):
    print('finishing', name, completed)

engine = pyttsx3.init('espeak')
engine.connect('started-utterance', onStart)
engine.connect('started-word', onWord)
engine.connect('finished-utterance', onEnd)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

run it

python test_pyttsx3.py

What should it do?

Speak - but also print out

word None 33 3
word None 37 4
word None 42 3
finishing None True
starting None
word None 1 3
word None 5 5
word None 11 5
word None 17 3

@DGrothe-PhD
Copy link

To avoid confusion, I just summarize the following steps to test

Fixed on Windows in my opinion!

@willwade
Copy link
Author

To avoid confusion, I just summarize the following steps to test

Fixed on Windows in my opinion!

yay! many thanks. I've been testing this on windows and Linux. There are a LOT of open issues in pyttsx3 that relate to this so I like to think we have crushed a lot in this PR :)

@willwade
Copy link
Author

Docker - WIP - instructions

https://gist.github.com/willwade/218ec9e356ae4c77b55ef282f051844d

NB: Im no docker expert.. It will at least show you word timings emitted.. so something is working...

@willwade
Copy link
Author

willwade commented Aug 4, 2024

NB: I dont mean to pile on any pressure but I'm looking at forking this repo to fix this issue more long term if this isnt accepted..(its causing headaches to keep linking to my repo in downstream projects needing eSpeak). there are so many forks of this library I dont really want to..

@DGrothe-PhD
Copy link

NB: I dont mean to pile on any pressure but I'm looking at forking this repo to fix this issue more long term if this isnt accepted..(its causing headaches to keep linking to my repo in downstream projects needing eSpeak). there are so many forks of this library I dont really want to..

I know, and, as it is better to be honest, it'll be much better if someone else can test it on a recent Linux environment.
Why not try and ask via LinkedIn?

@nateshmbhat
Copy link
Contributor

nateshmbhat commented Aug 15, 2024

@willwade thanks for these contributions
i'm pyttsx3 maintainer, can you please raise this pr to pyttsx3 repo ? if it works well , will get it merged and release it.

@willwade
Copy link
Author

@willwade thanks for these contributions i'm pyttsx3 maintainer, can you please raise this pr to pyttsx3 repo ? if it works well , will get it merged and release it.

yay. for sure! :)

@nateshmbhat
Copy link
Contributor

have published newer version with recent bug fix PRs merged to pyttsx3 in the latest version. Please check it out when you can 😃

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

Successfully merging this pull request may close these issues.

4 participants