Skip to content
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

Possible TTS implementation on macOS systems #271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

inb40
Copy link
Contributor

@inb40 inb40 commented May 27, 2023

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

@inb40 inb40 changed the title TTS on macOS systems Possible TTS on macOS systems May 27, 2023
@inb40 inb40 changed the title Possible TTS on macOS systems Possible TTS implementation on macOS systems May 27, 2023
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