-
Notifications
You must be signed in to change notification settings - Fork 11
Prioritize VoiceOver, Cocoa Example #27
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from enum import IntEnum | ||
| import ctypes | ||
| import os | ||
| import sys | ||
|
|
||
| # --- Load the SRAL C Library --- | ||
| try: | ||
|
|
@@ -28,7 +29,8 @@ class SRALEngine(IntEnum): | |
| SAPI = 1 << 6 | ||
| SPEECH_DISPATCHER = 1 << 7 | ||
| VOICE_OVER = 1 << 8 | ||
| AV_SPEECH = 1 << 9 | ||
| NS_SPEECH = 1 << 9 | ||
| AV_SPEECH = 1 << 10 | ||
|
Comment on lines
+32
to
+33
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NS_SPEECH was previously missing - it looks like we actually never updated these values to match the source library (which maybe we should change to read more directly?) - that's probably beyond the scope of this PR, but for now, these should at least match the options there |
||
|
|
||
| class SRALFeature(IntEnum): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #import <AppKit/AppKit.h> | ||
|
|
||
| #define SRAL_STATIC | ||
| #include <SRAL.h> | ||
|
|
||
| @interface AppDelegate : NSObject <NSApplicationDelegate> | ||
| @property (strong) NSWindow *window; | ||
| @property (strong) NSTextField *engineLabel; | ||
| @property (strong) NSTextField *speakingLabel; | ||
| @property (strong) NSTimer *speakingTimer; | ||
| @end | ||
|
|
||
| @implementation AppDelegate | ||
|
|
||
| - (void)applicationDidFinishLaunching:(NSNotification *)notification { | ||
| NSRect frame = NSMakeRect(200, 200, 400, 200); | ||
| self.window = [[NSWindow alloc] | ||
| initWithContentRect:frame | ||
| styleMask:(NSWindowStyleMaskTitled | | ||
| NSWindowStyleMaskClosable | | ||
| NSWindowStyleMaskMiniaturizable) | ||
| backing:NSBackingStoreBuffered | ||
| defer:NO]; | ||
| [self.window setTitle:@"SRAL Cocoa Example"]; | ||
|
|
||
| self.engineLabel = [NSTextField labelWithString:@"Engine: (initializing...)"]; | ||
| [self.engineLabel setFrame:NSMakeRect(20, 150, 360, 20)]; | ||
| [[self.window contentView] addSubview:self.engineLabel]; | ||
|
|
||
| self.speakingLabel = [NSTextField labelWithString:@"Speaking: No"]; | ||
| [self.speakingLabel setFrame:NSMakeRect(20, 125, 360, 20)]; | ||
| [[self.window contentView] addSubview:self.speakingLabel]; | ||
|
|
||
| NSButton *speakButton = [NSButton buttonWithTitle:@"Speak" | ||
| target:self | ||
| action:@selector(speakClicked:)]; | ||
| [speakButton setFrame:NSMakeRect(125, 70, 150, 40)]; | ||
| [[self.window contentView] addSubview:speakButton]; | ||
|
|
||
| if (!SRAL_Initialize(0)) { | ||
| [self.engineLabel setStringValue:@"Engine: Failed to initialize SRAL!"]; | ||
| return; | ||
| } | ||
|
|
||
| int engine = SRAL_GetCurrentEngine(); | ||
| const char *name = SRAL_GetEngineName(engine); | ||
| [self.engineLabel setStringValue: | ||
| [NSString stringWithFormat:@"Engine: %s", name ? name : "Unknown"]]; | ||
|
|
||
| // Continuously poll engine and speaking status | ||
| self.speakingTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 | ||
| target:self | ||
| selector:@selector(updateStatus:) | ||
| userInfo:nil | ||
| repeats:YES]; | ||
|
|
||
| [self.window makeKeyAndOrderFront:nil]; | ||
| [NSApp activateIgnoringOtherApps:YES]; | ||
| } | ||
|
|
||
| - (void)speakClicked:(id)sender { | ||
| SRAL_Speak("Hello, this is a test of the SRAL library.", true); | ||
| } | ||
|
|
||
| - (void)updateStatus:(NSTimer *)timer { | ||
| int engine = SRAL_GetCurrentEngine(); | ||
| const char *name = SRAL_GetEngineName(engine); | ||
| [self.engineLabel setStringValue: | ||
| [NSString stringWithFormat:@"Engine: %s", name ? name : "None"]]; | ||
|
|
||
| [self.speakingLabel setStringValue: | ||
| SRAL_IsSpeaking() ? @"Speaking: Yes" : @"Speaking: No"]; | ||
|
Comment on lines
+71
to
+72
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note - for VoiceOver, this value is always "No" - VoiceOver has a "fire-and-forget" system, which is more a quirk of that system, than it is a failing of this system |
||
| } | ||
|
|
||
| - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { | ||
| return YES; | ||
| } | ||
|
|
||
| - (void)applicationWillTerminate:(NSNotification *)notification { | ||
| [self.speakingTimer invalidate]; | ||
| SRAL_Uninitialize(); | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| int main(int argc, const char *argv[]) { | ||
| @autoreleasepool { | ||
| NSApplication *app = [NSApplication sharedApplication]; | ||
| [app setActivationPolicy:NSApplicationActivationPolicyRegular]; | ||
|
|
||
| AppDelegate *delegate = [[AppDelegate alloc] init]; | ||
| [app setDelegate:delegate]; | ||
|
|
||
| [app run]; | ||
| } | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this import was missing, and making it impossible to run this on Mac OS X, so including this now (it is used in the check below on line 10)