5 // Created by Ingmar Stein on 15.11.04.
6 // Copyright 2004-2006 The Growl Project. All rights reserved.
9 #import "GrowlSpeechPrefs.h"
10 #import "GrowlSpeechDefines.h"
11 #import <AppKit/NSSpeechSynthesizer.h>
13 @implementation GrowlSpeechPrefs
14 - (NSString *) mainNibName {
15 return @"GrowlSpeechPrefs";
18 - (void) awakeFromNib {
19 NSArray *availableVoices = [NSSpeechSynthesizer availableVoices];
20 NSEnumerator *voiceEnum = [availableVoices objectEnumerator];
21 NSMutableArray *voiceAttributes = [[NSMutableArray alloc] initWithCapacity:[availableVoices count]];
22 NSString *voiceIdentifier;
23 while ((voiceIdentifier=[voiceEnum nextObject])) {
24 [voiceAttributes addObject:[NSSpeechSynthesizer attributesForVoice:voiceIdentifier]];
26 [self setVoices:voiceAttributes];
27 [voiceAttributes release];
29 NSString *voice = nil;
30 READ_GROWL_PREF_VALUE(GrowlSpeechVoicePref, GrowlSpeechPrefDomain, NSString *, &voice);
31 NSUInteger row = NSNotFound;
33 CFMakeCollectable(voice);
34 row = [availableVoices indexOfObject:voice];
38 if (row == NSNotFound)
39 row = [availableVoices indexOfObject:[NSSpeechSynthesizer defaultVoice]];
41 if ((row == NSNotFound) && ([availableVoices count]))
44 if (row != NSNotFound) {
45 [voiceList selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
46 [voiceList scrollRowToVisible:row];
48 [voiceList setDoubleAction:@selector(previewVoice:)];
51 - (NSArray *) voices {
55 - (void) setVoices:(NSArray *)theVoices {
57 voices = [theVoices retain];
65 - (IBAction) previewVoice:(id)sender {
67 NSInteger row = [sender selectedRow];
70 if(lastPreview != nil && [lastPreview isSpeaking]) {
71 [lastPreview stopSpeaking];
73 NSString *voice = [[voices objectAtIndex:row] objectForKey:NSVoiceIdentifier];
74 NSSpeechSynthesizer *quickVoice = [[NSSpeechSynthesizer alloc] initWithVoice:voice];
75 [quickVoice startSpeakingString:[NSString stringWithFormat:NSLocalizedString(@"This is a preview of the %@ voice.", nil), [[voices objectAtIndex:row] objectForKey:NSVoiceName]]];
76 lastPreview = quickVoice;
80 - (IBAction) voiceClicked:(id)sender {
81 NSInteger row = [sender selectedRow];
84 NSString *voice = [[voices objectAtIndex:row] objectForKey:NSVoiceIdentifier];
85 WRITE_GROWL_PREF_VALUE(GrowlSpeechVoicePref, voice, GrowlSpeechPrefDomain);