added possibility to choose Voice

This commit is contained in:
Jeena Paradies 2011-12-01 16:01:42 +01:00
parent 2d5efe26f6
commit c854b97b29
6 changed files with 479 additions and 339 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges</key>
<true/>
</dict>
</plist>

View file

@ -11,6 +11,8 @@
@interface SpeakerAppDelegate : NSObject <NSApplicationDelegate, NSSpeechSynthesizerDelegate> { @interface SpeakerAppDelegate : NSObject <NSApplicationDelegate, NSSpeechSynthesizerDelegate> {
NSWindow *window; NSWindow *window;
NSTextView *textView; NSTextView *textView;
NSMenu *languageMenu;
NSPopUpButton *languageMenuPopupButton;
NSSpeechSynthesizer *synth; NSSpeechSynthesizer *synth;
NSRange oldRange; NSRange oldRange;
BOOL isNewLocation; BOOL isNewLocation;
@ -18,6 +20,8 @@
@property (assign) IBOutlet NSWindow *window; @property (assign) IBOutlet NSWindow *window;
@property (retain, nonatomic) IBOutlet NSTextView *textView; @property (retain, nonatomic) IBOutlet NSTextView *textView;
@property (assign) IBOutlet NSMenu *languageMenu;
@property (assign) IBOutlet NSPopUpButton *languageMenuPopupButton;
-(IBAction)speakAction:(id)sender; -(IBAction)speakAction:(id)sender;
-(IBAction)seekForward:(id)sender; -(IBAction)seekForward:(id)sender;
@ -26,4 +30,7 @@
-(void)stopSpeaking; -(void)stopSpeaking;
-(void)startSpeaking; -(void)startSpeaking;
- (void)changeLanguage:(id)sender;
- (void)changeVoiceGender:(id)sender;
@end @end

View file

@ -8,7 +8,13 @@
#import "SpeakerAppDelegate.h" #import "SpeakerAppDelegate.h"
@interface SpeakerAppDelegate (private)
- (void)initLanugageMenu;
@end
@implementation SpeakerAppDelegate @implementation SpeakerAppDelegate
@synthesize languageMenu;
@synthesize languageMenuPopupButton;
@synthesize window, textView; @synthesize window, textView;
@ -29,6 +35,49 @@
[textView setSelectedRange:aRange]; [textView setSelectedRange:aRange];
[textView scrollRangeToVisible:aRange]; [textView scrollRangeToVisible:aRange];
} }
[self initLanugageMenu];
}
- (void)initLanugageMenu
{
NSInteger start = [[NSUserDefaults standardUserDefaults] integerForKey:@"languageVoiceIndex"];
NSLocale *currentLocale = [NSLocale currentLocale];
NSArray *voices = [NSSpeechSynthesizer availableVoices];
[self.languageMenu removeAllItems];
for (NSInteger i = 0; i < [voices count]; i++)
{
NSDictionary *dict = [NSSpeechSynthesizer attributesForVoice:[voices objectAtIndex:i]];
if (i == 0) {
NSLog(@"%@", dict);
}
NSString *country = [currentLocale displayNameForKey:NSLocaleIdentifier value:[dict objectForKey:@"VoiceLocaleIdentifier"]];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ - %@", country, [dict objectForKey:@"VoiceName"]] action:@selector(changeLanguage:) keyEquivalent:@""];
item.tag = i;
[self.languageMenu addItem:item];
[item release];
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"languageVoiceIndex"] && [[dict objectForKey:@"VoiceName"] isEqualToString:@"Alex"])
{
start = i;
}
}
[self.languageMenuPopupButton selectItemAtIndex:start];
}
- (void)changeLanguage:(id)sender
{
NSInteger index = [(NSMenuItem *)sender tag];
NSString *voice = [[NSSpeechSynthesizer attributesForVoice:[[NSSpeechSynthesizer availableVoices] objectAtIndex:index]] objectForKey:@"VoiceIdentifier"];
[synth setVoice:voice];
[[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"languageVoiceIndex"];
[self.languageMenuPopupButton selectItemAtIndex:index];
} }
- (void)applicationWillTerminate:(NSNotification *)aNotification { - (void)applicationWillTerminate:(NSNotification *)aNotification {
@ -103,6 +152,11 @@
[textView display]; [textView display];
} }
- (void)changeVoiceGender:(id)sender
{
}
- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)success { - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)success {
[textView setEditable:YES]; [textView setEditable:YES];
} }