Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 通过终端在Cocoa应用程序中的语音_Objective C_Macos_Cocoa_Nstextfield - Fatal编程技术网

Objective c 通过终端在Cocoa应用程序中的语音

Objective c 通过终端在Cocoa应用程序中的语音,objective-c,macos,cocoa,nstextfield,Objective C,Macos,Cocoa,Nstextfield,我正在尝试制作一个Mac应用程序,使用“系统”在终端中使用say命令,说出用户输入的NSTextField文本。但是,Xcode不断给出错误 - (IBAction)speak:(id)sender{ system("say %@", [textinput stringValue]); } *text输入是NSTextField系统的IBOutlet以单个字符*作为参数,因此必须先格式化命令字符串,然后才能将其传递给系统: - (IBAction)speak:(id)sender {

我正在尝试制作一个Mac应用程序,使用“系统”在终端中使用
say
命令,说出用户输入的
NSTextField
文本。但是,Xcode不断给出错误

- (IBAction)speak:(id)sender{
    system("say %@", [textinput stringValue]);
}

*text输入是
NSTextField

系统的
IBOutlet
以单个字符*作为参数,因此必须先格式化命令字符串,然后才能将其传递给系统:

- (IBAction)speak:(id)sender {
    NSString *command = [NSString stringWithFormat:@"say %@", [textinput stringValue]];
    system([command UTF8String]);
}

系统将单个字符*作为参数,因此您必须先格式化命令字符串,然后才能将其传递给系统:

- (IBAction)speak:(id)sender {
    NSString *command = [NSString stringWithFormat:@"say %@", [textinput stringValue]];
    system([command UTF8String]);
}

无需调用系统命令,只需直接使用Cocoa语音合成API即可。比如说

NSSpeechSynthesizer* speechSynthesizer = [[NSSpeechSynthesizer alloc] init];
[speechSynthesizer startSpeakingString:[textinput stringValue]];

然后,设置语音和调整其他设置也很容易。

无需调用系统命令,只需直接使用Cocoa语音合成API即可。比如说

NSSpeechSynthesizer* speechSynthesizer = [[NSSpeechSynthesizer alloc] init];
[speechSynthesizer startSpeakingString:[textinput stringValue]];

然后,设置语音和调整其他设置也很容易。

您是否有任何理由尝试为该系统而不是NSSpeechSynthesizer类?NSSpeechSynthesizer类?以前从未听说过,它是如何工作的?你有没有任何理由尝试为这个系统而不是NSSpeechSynthesizer类?NSSpeechSynthesizer类?以前没有听说过,它是如何工作的?