Espeak - event loop and recurrent say calls fix#363
Open
willwade wants to merge 42 commits into
Open
Conversation
Collaborator
Author
|
NB I used test code of this @cclauss I'm not sure now how accurate this is to our pytest code.. import pyttsx3
from pyinstrument import Profiler
import time
# Initialize the pyttsx3 engine
engine = pyttsx3.init("espeak")
# Set up event listeners for debugging
def on_start(name):
print(f"[DEBUG] Started utterance: {name}")
print(f"Started utterance: {name}")
def on_word(name, location, length):
print(f"Word: {name} at {location} with length {length}")
# Interrupt the utterance if location is above a threshold to simulate test_interrupting_utterance
if location > 10:
print("Interrupting utterance by calling endLoop...")
engine.stop() # Directly call endLoop instead of stop
def on_end(name, completed):
print(f"Finished utterance: {name}, completed: {completed}")
# Connect the listeners
# engine.connect("started-utterance", on_start)
# engine.connect("started-word", on_word)
# engine.connect("finished-utterance", on_end)
# Demo for test_interrupting_utterance
def demo_interrupting_utterance():
print("\nRunning demo_interrupting_utterance...")
engine.say("The quick brown fox jumped over the lazy dog.")
engine.runAndWait()
# Demo for test_external_event_loop
def demo_external_event_loop():
print("\nRunning demo_external_event_loop...")
def external_loop():
# Simulate external loop iterations
for _ in range(5):
engine.iterate() # Process engine events
time.sleep(0.5) # Adjust timing as needed
engine.say("The quick brown fox jumped over the lazy dog.")
engine.startLoop(False) # Start loop without blocking
external_loop()
print("Calling endLoop from external demo...")
engine.endLoop() # End the event loop explicitly
# Demo for testing multiple `say` calls followed by `runAndWait`
def demo_multiple_say_calls():
print("\nRunning demo_multiple_say_calls...")
engine.say("The first sentence.")
engine.runAndWait() # Should speak "The first sentence."
print("Calling say after the first runAndWait()...")
engine.say("The second sentence follows immediately.")
engine.runAndWait() # Should speak "The second sentence follows immediately."
print("Calling say after the second runAndWait()...")
engine.say("Finally, the third sentence is spoken.")
engine.runAndWait() # Should speak "Finally, the third sentence is spoken."
# Run demos
demo_interrupting_utterance()
# Initialize the profiler
profiler = Profiler()
# Start profiling for the external event loop demo
profiler.start()
# Run the external event loop demo
demo_external_event_loop()
# Stop profiling
profiler.stop()
# Print the profiling report
profiler.print()
# Run the multiple `say` calls demo
demo_multiple_say_calls() |
cclauss
reviewed
Nov 5, 2024
cclauss
reviewed
Nov 5, 2024
cclauss
reviewed
Nov 5, 2024
cclauss
reviewed
Nov 5, 2024
cclauss
reviewed
Nov 5, 2024
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
cclauss
reviewed
Nov 13, 2024
| steps: | ||
| - if: runner.os == 'Linux' | ||
| run: sudo apt-get update -q -q && sudo apt-get install --yes espeak-ng libespeak1 | ||
| run: sudo apt-get update -q -q && sudo apt-get install --yes espeak-ng libespeak1 alsa-utils |
Collaborator
There was a problem hiding this comment.
Suggested change
| run: sudo apt-get update -q -q && sudo apt-get install --yes espeak-ng libespeak1 alsa-utils | |
| run: sudo apt-get update -q -q && sudo apt-get install --yes alsa-utils espeak-ng libespeak1 |
Collaborator
|
modprobe: FATAL: Module snd-dummy not found in directory /lib/modules/6.5.0-1025-azure ??? |
cclauss
reviewed
Nov 13, 2024
Collaborator
|
Maybe skip the tests AFTER tests/test_pyttsx3.py::test_changing_volume PASSED if $CI is defined. |
cclauss
requested changes
Nov 15, 2024
cclauss
reviewed
Nov 15, 2024
| from tempfile import NamedTemporaryFile | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) |
Collaborator
There was a problem hiding this comment.
Great! Now we need to use logger instead of logger below.
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
cclauss
requested changes
Nov 15, 2024
cclauss
left a comment
Collaborator
There was a problem hiding this comment.
Please do not merge with failing tests.
Collaborator
Author
No worries! I wont! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So this fixes
it now has its own internal queue - which seems crazy since driver has a queue but it just was not easy making use of it
I feel this should be ok since sapi and mac dont really make use of the driver queue..
In time this whole library needs better reactoring around queues. Its really horrible to get your head around.
@cclauss - can you run this through your tests - it is an attempt to fix the external event loop
Its got a lot of debug lines in it ..
If it basically works i'll remove these.