我试图制作一个Mac应用程序,用于说明用户输入的NSTextField
文本,使用“system”在终端中使用say
命令。但是,Xcode不断给出错误。在可可应用程序中通过终端讲话
- (IBAction)speak:(id)sender{
system("say %@", [textinput stringValue]);
}
*的TextInput是NSTextField
的IBOutlet
。
我试图制作一个Mac应用程序,用于说明用户输入的NSTextField
文本,使用“system”在终端中使用say
命令。但是,Xcode不断给出错误。在可可应用程序中通过终端讲话
- (IBAction)speak:(id)sender{
system("say %@", [textinput stringValue]);
}
*的TextInput是NSTextField
的IBOutlet
。
系统采用单个字符*作为参数,所以你必须格式化命令字符串,然后才能将其传递给系统:
- (IBAction)speak:(id)sender {
NSString *command = [NSString stringWithFormat:@"say %@", [textinput stringValue]];
system([command UTF8String]);
}
感谢您的帮助:) – haseo98
有没有必要调出该系统命令,只是使用可可语音合成API直接。例如
NSSpeechSynthesizer* speechSynthesizer = [[NSSpeechSynthesizer alloc] init];
[speechSynthesizer startSpeakingString:[textinput stringValue]];
然后很容易设置语音和调整其他设置。
究竟是什么错误? –
是否有任何理由试图让系统为此而不是NSSpeechSynthesizer类? – Abizern
NSSpeechSynthesizer class?,之前听说过它,它是如何工作的? – haseo98