diff --git a/.gitignore b/.gitignore index 8d5b911..43b41bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.*env/ build/ dist/' docs/_build diff --git a/accessible_output2/outputs/__init__.py b/accessible_output2/outputs/__init__.py index 5142a45..79b57aa 100644 --- a/accessible_output2/outputs/__init__.py +++ b/accessible_output2/outputs/__init__.py @@ -34,6 +34,7 @@ def _load_com(*names): if platform.system() == "Darwin": from . import voiceover + from . import nsspeechsynthesizer if platform.system() == "Linux": from . import speech_dispatcher diff --git a/accessible_output2/outputs/nsspeechsynthesizer.py b/accessible_output2/outputs/nsspeechsynthesizer.py new file mode 100644 index 0000000..1710b86 --- /dev/null +++ b/accessible_output2/outputs/nsspeechsynthesizer.py @@ -0,0 +1,28 @@ +from platform import system as get_current_system +from .base import Output + +class MacSpeech(Output): + + """Speech output supporting Apple MacOS NSSpeechSynthesizer.""" + + name = "MacSpeech" + priority = 101 + system_output = True + + def __init__(self, *args, **kwargs): + from AppKit import NSSpeechSynthesizer + self.synth = NSSpeechSynthesizer.alloc().init() + + def speak(self, text: str, interrupt: bool = False) -> bool: + if interrupt: + self.silence() + return self.synth.startSpeakingString_(text) + + def silence(self): + self.synth.stopSpeaking() + + def is_active(self): + return get_current_system() == "Darwin" + + +output_class = MacSpeech diff --git a/requirements.txt b/requirements.txt index 26456e2..ede44f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ libloader platform_utils +pyobjc; sys_platform == 'darwin'