Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 NSSpeech合成器-播放声音_Objective C_Cocoa - Fatal编程技术网

Objective c NSSpeech合成器-播放声音

Objective c NSSpeech合成器-播放声音,objective-c,cocoa,Objective C,Cocoa,我正在玩NSSpeechSynthesizer类,但由于某些原因,声音无法播放。这是我使用的源代码 #import <Foundation/Foundation.h> #import <AppKit/`NSSpeechSynthesizer.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSSpeechSynthesizer *sp = [[NSSpeechSyn

我正在玩NSSpeechSynthesizer类,但由于某些原因,声音无法播放。这是我使用的源代码

#import <Foundation/Foundation.h>
#import <AppKit/`NSSpeechSynthesizer.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        NSSpeechSynthesizer *sp = [[NSSpeechSynthesizer alloc] init];
        [sp setVolume:100.0];
        [sp startSpeakingString:@"Just testing"];

    }
    return 0;
}
#导入
#进口
int main(int argc,const char*argv[]
{
@自动释放池{
NSSpeechSynthesizer*sp=[[NSSpeechSynthesizer alloc]init];
[sp设定音量:100.0];
[sp StartPeakingString:@“刚刚测试”];
}
返回0;
}

是的,扬声器已打开

您的应用程序在有机会实际播放声音之前退出。您可以通过在代码中添加无限循环来检查这一点:

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSSpeechSynthesizer *sp = [[NSSpeechSynthesizer alloc] init];
        [sp setVolume:100.0];
        [sp startSpeakingString:@"Just testing"];
        while(YES);
    }
    return 0;
}