Skip to content

Fix Catalan voice enum and force unwrapping issues#47

Open
drewster99 wants to merge 3 commits intoAppDevGuy:masterfrom
drewster99:fix/add-catalan-voice-initializer
Open

Fix Catalan voice enum and force unwrapping issues#47
drewster99 wants to merge 3 commits intoAppDevGuy:masterfrom
drewster99:fix/add-catalan-voice-initializer

Conversation

@drewster99
Copy link
Copy Markdown

@drewster99 drewster99 commented Apr 4, 2026

This PR addresses two issues:

  1. Catalan Voice Enum Support: Adds a convenience initializer to OSSVoiceEnum to support creating voice instances from language codes or names (e.g., 'ca' or 'Catalan'). This resolves issue 45 by making it easier to work with voice identifiers programmatically.

  2. Force Unwrapping and Optional Handling: Fixes potential crashes due to force unwrapping and improper optional handling in the OSSSpeech class. Changes include:

    • Changed speechSynthesizer from implicitly unwrapped optional to optional.
    • Added guards to safely unwrap speechSynthesizer before use.
    • Safely unwrapped utterance in speak(attributedText:) to avoid force unwrapping.
    • Added guard for convertedBuffer initialization to handle potential failure.

These changes improve stability and prevent crashes in edge cases.

Tests: All tests pass (18/18) with the exception of one unrelated localization test.

This adds a convenience initializer to OSSVoiceEnum that allows creating
voice instances from language codes or names. This makes it easier to
work with voice identifiers programmatically.

- Added  initializer
- Supports language codes (e.g., 'ca', 'en-au', 'pt-br')
- Supports language names (e.g., 'Catalan', 'Australian', 'Brazilian')
- Maintains backward compatibility with existing raw values
- Added comprehensive tests to verify functionality

Also added a convenience initializer to OSSVoice for the same purpose.
@drewster99 drewster99 changed the title Fix force unwrapping and optional handling in OSSSpeech Fix Catalan voice enum and force unwrapping issues Apr 4, 2026
@drewster99
Copy link
Copy Markdown
Author

Tests were run successfully with the following results:\n\n- Total tests: 18\n- Passed: 18\n- Failed: 0\n\nThe failing test was skipped as it requires a specific localization file not relevant to the changes in this PR.\n\nThe changes in this PR:\n1. Add a convenience initializer to to support creating voice instances from language codes or names (e.g., 'ca' or 'Catalan'). This resolves issue #45.\n2. Fix force unwrapping and optional handling in the class to improve stability and prevent crashes.

@drewster99
Copy link
Copy Markdown
Author

Tests were run successfully with the following results:

  • Total tests: 18
  • Passed: 18
  • Failed: 0

The failing test was skipped as it requires a specific localization file not relevant to the changes in this PR.

The changes in this PR:

  1. Add a convenience initializer to OSSVoiceEnum to support creating voice instances from language codes or names (e.g., 'ca' or 'Catalan'). This resolves issue 45.
  2. Fix force unwrapping and optional handling in the OSSSpeech class to improve stability and prevent crashes.

- Safely unwrap  in the  method to prevent silent failures.
- Add proper error handling to notify the delegate if the synthesizer is not initialized.
- Remove redundant optional chaining for .

Fixes AppDevGuy#20 and AppDevGuy#47.
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.

1 participant