MRSpeechDispatcher
提供了一个易于使用的接口,用于在 iOS 设备上从文本生成合成语音
MRSpeechDispatcher *dispatcher = MRSpeechDispatcher.defaultSpeechDispatcher;
dispatcher.reusedSynthesizer = [[AVSpeechSynthesizer alloc] init];
[dispatcher speechText:@"Now relax." withAnimus:MRSpeechAnimusGlad];
[dispatcher speechText:@"And close your eyes." withAnimus:MRSpeechAnimusRegular];
[dispatcher keepQuiteFor:2];
[dispatcher speechText:@"Well done!" withAnimus:MRSpeechAnimusGlad];
[dispatcher speechText:@"See you the next session!" withAnimus:MRSpeechAnimusHurry];
在上述示例中,调度器通过将生成的 AVSpeechUtterance
实例包装成 MRSpeechUtteranceOperation
对象并添加到其 NSOperationQueue
中来排队将要说的文本。
但 MRSpeechUtteranceOperation
也可以像任何其他 NSOperation
实例一样独立地创建和使用
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"hello"];
NSOperation *operation = [MRSpeechUtteranceOperation speechOperationWithUtterance:utterance];
[operation start];
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
执行以下步骤
MROperation
类添加到您的项目中(请参阅 https://www.github.com/hectr/MROperation)。MRSpeechDispatcher 使用 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。