Possible TTS implementation on macOS systems #271
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.
In this PR, I've made an implementation for TTS on macOS systems. This has been implemented with a new class named MacTTSContext, which extends the ITTSContext interface.
It runs the
say
(https://ss64.com/osx/say.html) command available on macOS systems, passing in arguments to customize and support most features the Windows implementation has. It runs each TTS execution in a new process (inefficient, but haven't found any other way), so it does not block the game while processing. There has been no noticeable latency in my testing.I think this implementation is the next best thing to using the native speech synthesizer API on macOS, which can't be used (AFAIK) in the project unless you create a build for macOS.
Key points of the implementation:
Voice Selection: Uses "Alex" for male characters and "Samantha" for female characters. These are default voices on macOS systems and should be available on most of them. If these voices are not available, the system will fall back to the default system voice.
Pitch Adjustment: Uses the
pbas
command to adjust the pitch of the TTS voice.Note: negative pitch values are not supported by the
pbas
command, so 'deeper' voices aren't supported. You can only make the pitch higher, not lower than the default. The lower-half of the slider in the game settings will only result in the default pitch.Input Sanitization: User input is sanitized before processing to remove any 'say' command sequence injections, ensuring a consistent voice throughout the game.
Exception Handling: Exceptions during the execution of the 'say' command are silently handled to prevent game disruptions.
Tested on macOS Monterey.
Preview of both voices in the game
Male voice (Alex): https://streamable.com/2gfkbt
Female voice (Samantha): https://streamable.com/nzf9x5
Testing at a lot (most action I've been able to get): https://streamable.com/3gin92
Please let me know if there are any areas you want me to focus on for further refining or if you have any questions about the implementation. Thanks @riperiperi!!