我最近实现了 iOS 7 TTS API,但它无法正常工作。
在.h中:
#import <AVFoundation/AVFoundation.h>
@interface MainViewController : UIViewController <AVSpeechSynthesizerDelegate>
在 .m 中:
@interface MainViewController ()
@property (nonatomic, strong) AVSpeechSynthesizer* talker;
@end
- (void)viewDidLoad
{
AVSpeechUtterance *utter = [[AVSpeechUtterance alloc] initWithString:@"Hello World"];
utter.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[utter setRate:0.2f];
if (!self.talker) {
self.talker = [AVSpeechSynthesizer new];
}
self.talker.delegate = self;
[self.talker speakUtterance:utter];
}
我还添加了 AVFoundation.framework
。我不知道问题是什么,但什么也没说。感谢您的帮助。
最佳答案
你正在创建你的合成器,然后你的方法结束,合成器在它可以做任何事情之前消失在一阵烟雾中。如果您想让它说话,请保留它(例如在特性中),以便它活得足够好。
关于iOS 7 文本转语音 API 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24560210/