gpt4 book ai didi

objective-c - NSSpeechSynthesizer - 播放声音

转载 作者:行者123 更新时间:2023-12-03 17:12:10 26 4
gpt4 key购买 nike

我正在使用 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;
}

关于objective-c - NSSpeechSynthesizer - 播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826176/

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