NSSpeechSynthesizer语言 - 播放声音



我正在使用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[])
{
    @autoreleasepool {
        NSSpeechSynthesizer *sp = [[NSSpeechSynthesizer alloc] init];
        [sp setVolume:100.0];
        [sp startSpeakingString:@"Just testing"];
        while(YES);
    }
    return 0;
}

最新更新