source: trunk/Cocoa/Pester/Source/PSSpeechAlert.m@ 432

Last change on this file since 432 was 366, checked in by Nicholas Riley, 17 years ago

Info-Pester.plist: Updated for build 23.

NJRHotKey.m: Cosmetic cleanup.

PSAlarm.[hm]: Fix -[PSAlarm time] to work properly, though it no
longer has any clients.

PSSnoozeUntilController.m: Fix snooze until time being off by an hour
as displayed, or if edited, in some time zones.

PSSpeechAlert.m: Display the voice name instead of its identifier in
the description.

Pester.xcodeproj: Misc.

release-notes.html: Updated for build 23.

File size: 2.6 KB
Line 
1//
2// PSSpeechAlert.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSSpeechAlert.h"
10#import "PSAlarmAlertController.h"
11#import "NSDictionary-NJRExtensions.h"
12
13// property list keys
14static NSString * const PLAlertVoice = @"voice"; // NSString
15
16@implementation PSSpeechAlert
17
18+ (PSSpeechAlert *)alertWithVoice:(NSString *)aVoice;
19{
20 return [[[self alloc] initWithVoice: aVoice] autorelease];
21}
22
23- (id)initWithVoice:(NSString *)aVoice;
24{
25 if ( (self = [super init]) != nil) {
26 voice = [aVoice retain];
27 }
28 return self;
29}
30
31- (void)dealloc;
32{
33 [[NSNotificationCenter defaultCenter] removeObserver: self];
34 [speaker release]; speaker = nil;
35 [voice release]; voice = nil;
36 [super dealloc];
37}
38
39- (NSString *)voice;
40{
41 return voice;
42}
43
44- (void)_stopSpeaking:(NSNotification *)notification;
45{
46 [speaker stopSpeaking]; // triggers didFinishSpeaking:
47}
48
49- (void)triggerForAlarm:(PSAlarm *)anAlarm;
50{
51 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(_stopSpeaking:) name: PSAlarmAlertStopNotification object: nil];
52
53 if ( (speaker = [[NSSpeechSynthesizer alloc] initWithVoice: voice]) == nil) return;
54 alarm = anAlarm;
55 [speaker setDelegate: self];
56 [speaker startSpeakingString: [alarm message]];
57}
58
59- (NSAttributedString *)actionDescription;
60{
61 NSMutableAttributedString *string = [[@"Speak message with voice " small] mutableCopy];
62 NSString *voiceName = [[NSSpeechSynthesizer attributesForVoice: voice] objectForKey: NSVoiceName];
63 if (voiceName == nil)
64 voiceName = voice;
65 [string appendAttributedString: [voiceName underlined]];
66 return [string autorelease];
67}
68
69#pragma mark property list serialization (Pester 1.1)
70
71- (NSDictionary *)propertyListRepresentation;
72{
73 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
74 if (voice == nil)
75 @throw [NSException exceptionWithName: NSInvalidArgumentException
76 reason: @"The selected voice is not available." userInfo: nil];
77 [plAlert setObject: voice forKey: PLAlertVoice];
78 return [plAlert autorelease];
79}
80
81- (id)initWithPropertyList:(NSDictionary *)dict;
82{
83 if ( (self = [self init]) != nil) {
84 voice = [[dict objectForRequiredKey: PLAlertVoice] retain];
85 }
86 return self;
87}
88
89@end
90
91@implementation PSSpeechAlert (NSSpeechSynthesizerDelegate)
92
93- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking;
94{
95 [self completedForAlarm: alarm];
96 [speaker release]; speaker = nil;
97}
98
99@end
Note: See TracBrowser for help on using the repository browser.