3
我正在編寫一個簡單的程序,該程序基於使用NSSpeechSynthesizer講短語的Cocoa Book的示例。我想知道如何更改用於合成階段的語言。NSSpeechSynthesizer更改語言
#import "PHAppDelegate.h"
@implementation PHAppDelegate
@synthesize window = _window;
@synthesize textField = _textField;
- (id)init{
self = [super init];
if(self){
NSLog(@"init");
_speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (IBAction)stopIt:(id)sender {
NSLog(@"stoppping");
[_speechSynth stopSpeaking];
}
- (IBAction)sayit:(id)sender {
NSString *string = [_textField stringValue];
if([string length] == 0){
NSLog(@"There is no text to speech.");
return;
}
NSString *voiceID =[[NSSpeechSynthesizer availableVoices] objectAtIndex:10];
[_speechSynth setVoice:voiceID];
[_speechSynth startSpeakingString:string];
NSLog(@"Have started to say: %@", string);
}
@end
此代碼正常工作。