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.
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!!
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 thepbas
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!!