Changeset 364 for trunk/Cocoa/Pester/Source/NJRVoicePopUpButton.m
- Timestamp:
- 11/28/07 01:29:26 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRVoicePopUpButton.m
r355 r364 15 15 NSMenu *menu; 16 16 NSMenuItem *item; 17 NSArray *voice Names = [SUSpeaker voiceNames];17 NSArray *voices = [NSSpeechSynthesizer availableVoices]; 18 18 19 19 [self removeAllItems]; … … 24 24 [item setEnabled: NO]; 25 25 [menu addItem: [NSMenuItem separatorItem]]; 26 if (voice Names == nil || [voiceNames count] == 0) {26 if (voices == nil || [voices count] == 0) { 27 27 item = [menu addItemWithTitle: NSLocalizedString(@"Can't locate voices", "Voice popup menu item surrogate for voice list if no voices are found") action: nil keyEquivalent: @""]; 28 28 [item setEnabled: NO]; 29 29 } else { 30 NSEnumerator *e = [voiceNames objectEnumerator]; 31 NSString *voiceName; 32 while ( (voiceName = [e nextObject]) != nil) { 33 item = [menu addItemWithTitle: voiceName action: @selector(_previewVoice) keyEquivalent: @""]; 30 NSEnumerator *e = [voices objectEnumerator]; 31 NSString *voice; 32 while ( (voice = [e nextObject]) != nil) { 33 item = [menu addItemWithTitle: 34 [[NSSpeechSynthesizer attributesForVoice: voice] objectForKey: NSVoiceName] 35 action: @selector(_previewVoice) keyEquivalent: @""]; 36 [item setRepresentedObject: voice]; 34 37 [item setTarget: self]; 35 38 } 36 39 } 37 if (_speaker == nil) [self selectItemWithTitle: [SUSpeaker defaultVoice]]; 40 if (_speaker == nil) 41 [self selectItemAtIndex: [menu indexOfItemWithRepresentedObject: [NSSpeechSynthesizer defaultVoice]]]; 38 42 } 39 43 … … 54 58 } 55 59 56 - ( SUSpeaker *)_speaker;60 - (NSSpeechSynthesizer *)_speaker; 57 61 { 58 if (_speaker == nil) _speaker = [[ SUSpeaker alloc] init];62 if (_speaker == nil) _speaker = [[NSSpeechSynthesizer alloc] initWithVoice: nil]; 59 63 return _speaker; 60 64 } … … 68 72 - (void)setVoice:(NSString *)voice; 69 73 { 70 int voiceIdx = [self indexOfItemWith Title: voice];74 int voiceIdx = [self indexOfItemWithRepresentedObject: voice]; 71 75 if (voiceIdx == -1) { 72 76 [self _invalidateVoiceSelection]; … … 78 82 - (void)_previewVoice; 79 83 { 80 NSString *voice Name = [self titleOfSelectedItem];84 NSString *voice = [[self selectedItem] representedObject]; 81 85 NSString *previewString = nil; 82 VoiceSpec voice;83 OSStatus err = noErr;84 VoiceDescription info;85 short voiceIndex = [[SUSpeaker voiceNames] indexOfObject: voiceName] + 1;86 86 87 87 [_speaker stopSpeaking]; 88 88 89 if ( (err = GetIndVoice(voiceIndex, &voice)) != noErr) { 90 NSBeginAlertSheet(@"Voice not available", nil, nil, nil, [self window], nil, nil, nil, nil, NSLocalizedString(@"The voice '%@' you selected could not be used. An error of type %ld occurred while attempting to retrieve voice information.", "Message displayed in alert sheet when GetIndVoice returns an error"), voiceName, err); 89 if (![[self _speaker] setVoice: voice]) { 90 // XXX localize title 91 NSBeginAlertSheet(@"Voice not available", nil, nil, nil, [self window], nil, nil, nil, nil, NSLocalizedString(@"The voice '%@' you selected could not be used.", "Message displayed in alert sheet when -[NSSpeechSynthesizer setVoice:] returns an error"), [self titleOfSelectedItem]); 91 92 [self _invalidateVoiceSelection]; 92 93 return; … … 94 95 95 96 if (_delegate != nil && [_delegate respondsToSelector: @selector(voicePopUpButton:previewStringForVoice:)]) { 96 previewString = [_delegate voicePopUpButton: self previewStringForVoice: voice Name];97 previewString = [_delegate voicePopUpButton: self previewStringForVoice: voice]; 97 98 } 98 99 99 if (previewString == nil) { 100 err = GetVoiceDescription(&voice, &info, sizeof(info)); 101 if (err != noErr || info.comment[0] == 0) 102 previewString = voiceName; 103 else { 104 previewString = (NSString *)CFStringCreateWithPascalString(NULL, info.comment, kCFStringEncodingMacRoman); 105 [previewString autorelease]; 106 } 107 } 100 if (previewString == nil) 101 previewString = [[NSSpeechSynthesizer attributesForVoice: voice] objectForKey: NSVoiceDemoText]; 108 102 109 [[self _speaker] setVoice: voiceIndex]; 110 [_speaker speakText: previewString]; 103 [_speaker startSpeakingString: previewString]; 111 104 } 112 105
Note:
See TracChangeset
for help on using the changeset viewer.