gpt4 book ai didi

objective-c - NSSpeechSynthesizer 更改语言

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:42 25 4
gpt4 key购买 nike

我正在编写一个基于 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

这段代码工作正常。

最佳答案

for (NSString *voiceIdentifierString in [NSSpeechSynthesizer availableVoices]) {
NSString *voiceLocaleIdentifier = [[NSSpeechSynthesizer attributesForVoice:voiceIdentifierString] objectForKey:NSVoiceLocaleIdentifier];
NSLog(@"%@ speaks %@", voiceIdentifierString, voiceLocaleIdentifier);

参见 Voice Attributes Keys

关于objective-c - NSSpeechSynthesizer 更改语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13368516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com