From 0a2f84c8b34e903707474c6fda9ffc21a9a41ab9 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sun, 2 Dec 2018 18:47:51 -0800 Subject: [PATCH] Adds a speech synthesizer class --- rumps/rumps.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rumps/rumps.py b/rumps/rumps.py index 5321537..232e988 100644 --- a/rumps/rumps.py +++ b/rumps/rumps.py @@ -20,7 +20,8 @@ from Foundation import (NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSSearchPathForDirectoriesInDomains, NSMakeRect, NSLog, NSObject) -from AppKit import NSApplication, NSStatusBar, NSMenu, NSMenuItem, NSAlert, NSTextField, NSSecureTextField, NSImage +from AppKit import (NSApplication, NSStatusBar, NSMenu, NSMenuItem, NSAlert, NSTextField, NSSecureTextField, NSImage, + NSSpeechSynthesizer) from PyObjCTools import AppHelper import inspect @@ -46,9 +47,28 @@ def _log(*args): else: def _log(*_): pass + + debug_mode(False) +class SpeechSynthesizer: + """Wrapper for Objective-C's NSSpeechSynthesizer class. + + Implements core functionality of speech in rumps. + """ + def __init__(self, message): + self.synth = NSSpeechSynthesizer.alloc().initWithVoice_(None) + self.synth.startSpeakingString_(message) + + def stop(self): + """ + Stops the current speech, if speaking. + """ + if self.synth.speaking: + self.synth.stopSpeaking() + + def alert(title=None, message='', ok=None, cancel=None, other=None, icon_path=None): """Generate a simple alert window.