-
Notifications
You must be signed in to change notification settings - Fork 342
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
DRAFT: attempt to fix hang on voices for espeak in test #386
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a573fda
attempt to fix hang on voices for espeak in test
willwade c8dcffe
bringing back in comments
willwade 718c2fd
attempt adding a test - resetonrestart
willwade 39cf519
Update test_engines.py
willwade f8eb6d2
maybe we just have a problem in espeak..
willwade 7c5dae8
encode all stdout output using utf-8
willwade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import pyttsx3 | ||
|
||
sys.stdout.reconfigure(encoding="utf-8") | ||
quick_brown_fox = "The quick brown fox jumped over the lazy dog." | ||
|
||
|
||
|
@@ -38,33 +39,41 @@ def test_espeak_voices(driver_name): | |
pytest.skip(f"Skipping eSpeak-specific test for {driver_name}.") | ||
|
||
engine = pyttsx3.init(driver_name) | ||
print(list(pyttsx3._activeEngines)) | ||
print(engine) | ||
assert str(engine) == "espeak", "Expected engine name to be espeak" | ||
voice = engine.getProperty("voice") | ||
if voice: # eSpeak-NG Windows v1.52-dev returns None | ||
assert ( | ||
voice == "English (Great Britain)" | ||
), f"Expected {engine} default voice to be 'English (Great Britain)'" | ||
voices = engine.getProperty("voices") | ||
print(f"{engine} has {len(voices) = } voices.") | ||
original_voice = engine.getProperty("voice") | ||
|
||
assert str(engine) == "espeak", "Expected engine name to be 'espeak'" | ||
|
||
# Retrieve and print voices without modifying `voice` property | ||
# Linux eSpeak-NG v1.50 has 109 voices, | ||
# macOS eSpeak-NG v1.51 has 131 voices, | ||
# Windows eSpeak-NG v1.52-dev has 221 voices. | ||
assert len(voices) in {109, 131, 221}, f"Expected 109, 131, 221 voices in {engine}" | ||
# print("\n".join(voice.id for voice in voices)) | ||
voices = engine.getProperty("voices") | ||
print(f"{engine} has {len(voices)} voices.") | ||
assert len(voices) in { | ||
109, | ||
131, | ||
221, | ||
}, f"Expected 109, 131, or 221 voices in {engine}" | ||
|
||
# Filter English voices | ||
english_voices = [voice for voice in voices if voice.id.startswith("English")] | ||
# Linux eSpeak-NG v1.50 has 7 English voices, | ||
# macOS eSpeak-NG v1.51 and Windows eSpeak-NG v1.52-dev have 8 English voices. | ||
assert len(english_voices) in {7, 8}, "Expected 7 or 8 English voices in {engine}" | ||
assert len(english_voices) in {7, 8}, "Expected 7 or 8 English voices" | ||
|
||
# Queue a single utterance for each voice without calling `runAndWait()` in a loop | ||
names = [] | ||
for _voice in english_voices: | ||
engine.setProperty("voice", _voice.id) | ||
# English (America, New York City) --> America, New York City | ||
name = _voice.id[9:-1] | ||
name = _voice.id[9:-1] # Extract name for display | ||
names.append(name) | ||
engine.say(f"{name} says hello") | ||
engine.runAndWait() # TODO: Remove this line when multiple utterances work! | ||
engine.say(f"{name} says hello") # Queue the utterance | ||
|
||
# Run all queued utterances at once | ||
engine.runAndWait() | ||
|
||
# Verify the names collected against expected values | ||
name_str = "|".join(names) | ||
expected = ( | ||
"Caribbean|Great Britain|Scotland|Lancaster|West Midlands" | ||
|
@@ -73,8 +82,47 @@ def test_espeak_voices(driver_name): | |
no_nyc = expected.rpartition("|")[0] | ||
assert name_str in {expected, no_nyc}, f"Expected '{expected}' or '{no_nyc}'." | ||
print(f"({name_str.replace('|', ' ; ')})", end=" ", flush=True) | ||
engine.runAndWait() | ||
engine.setProperty("voice", voice) # Reset voice to original value | ||
Comment on lines
-76
to
-77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Listen to the tests that come after this one to see why restoring defaults makes things sound more intuitive. Perhaps we need a test that is.
|
||
|
||
# Reset to the original voice and stop engine | ||
engine.setProperty("voice", original_voice) | ||
engine.stop() | ||
|
||
|
||
@pytest.mark.parametrize("driver_name", ["espeak"]) | ||
def test_voice_reset_on_restart(driver_name): | ||
engine = pyttsx3.init(driver_name) | ||
original_voice = engine.getProperty("voice") | ||
|
||
# Get available voices | ||
voices = engine.getProperty("voices") | ||
print(f"Available voices: {[voice.id for voice in voices]}") | ||
if len(voices) <= 1: | ||
pytest.skip("No additional voices available to test voice change.") | ||
|
||
# Find a different voice | ||
new_voice = next((v.id for v in voices if v.id != original_voice), None) | ||
if new_voice is None: | ||
pytest.skip("No different voice available to test voice change.") | ||
|
||
# Attempt to change the voice | ||
print(f"Original voice: {original_voice}") | ||
print(f"Attempting to change to voice: {new_voice}") | ||
engine.setProperty("voice", new_voice) | ||
current_voice = engine.getProperty("voice") | ||
print(f"Current voice after change: {current_voice}") | ||
|
||
if current_voice == original_voice: | ||
pytest.skip("Voice change is not supported or failed for the espeak engine.") | ||
|
||
# Check that the engine resets to the original voice after restart | ||
engine.stop() | ||
engine = pyttsx3.init(driver_name) # Re-initialize | ||
assert ( | ||
engine.getProperty("voice") == original_voice | ||
), "Voice did not reset to default after restart." | ||
|
||
# Clean up | ||
engine.setProperty("voice", original_voice) | ||
engine.stop() | ||
|
||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better documentation of what the code does than ~ Extract hame for display.