AVSpeechSynthesizer的队列管理系统
将QHSpeechSyntesizerQueue.h和QHSpeechSyntesizerQueue.m拖放到您的项目中,然后
#import "QHSpeechSyntesizerQueue.h"
QHSpeechSyntesizerQueue *syntesizerQueue = [[QHSpeechSyntesizerQueue alloc] init];
[syntesizerQueue readLast:@"This message will be added to the end of the queue" withLanguage:@"en_US" andRate:@"0.2"];
[syntesizerQueue readNext:@"This message will be read next" withLanguage:@"en_US" andRate:@"0.2" andClearQueue:NO];
如果您将andClearQueue:
设置为YES
,则队列将被清除,这将是最后要读取的消息。
[syntesizerQueue readImmediately:@"This message will be read next" withLanguage:@"en_US" andRate:@"0.2" andClearQueue:NO];
如果您将andClearQueue:
设置为YES
,则队列将被清除,这将是最后要读取的消息。
停止队列播放并立即清除队列。
[syntesizerQueue stop];
停止队列播放并清除队列。如果当前正在读取某些内容,它将在之后停止。
[syntesizerQueue stopAfterCurrent];
立即暂停队列播放。
[syntesizerQueue pause];
暂停队列播放。如果当前正在读取某些内容,它将在之后暂停。
[syntesizerQueue pauseAfterCurrent];
继续队列播放。
[syntesizerQueue resume];
清除队列。如果正在读取内容,则不会中断,如果未暂停/停止,则将阅读未来添加的消息。
[syntesizerQueue clearQueue];
将此设置为YES,当读取字符串时,将静音所有设备的音频会话。默认值为YES。
syntesizerQueue.duckOthers = YES;
读取消息之前的延迟。默认为0.0
syntesizerQueue.preDelay = 1.0;
读取消息之后的延迟。默认为0.0
syntesizerQueue.postDelay = 1.0;
您可以设置一个 QHSpeechSynthesizerQueueDelegate
来接收播放事件的通知。
@protocol QHSpeechSynthesizerQueueDelegate <NSObject>
@optional
- (void)speechSynthesizerQueueDidStartTalking:(QHSpeechSynthesizerQueue *)queue;
- (void)speechSynthesizerQueueDidFinishTalking:(QHSpeechSynthesizerQueue *)queue;
- (void)speechSynthesizerQueueDidPauseTalking:(QHSpeechSynthesizerQueue *)queue;
- (void)speechSynthesizerQueueDidContinueTalking:(QHSpeechSynthesizerQueue *)queue;
- (void)speechSynthesizerQueueDidCancelTalking:(QHSpeechSynthesizerQueue *)queue;
- (void)speechSynthesizerQueueWillStartTalking:(QHSpeechSynthesizerQueue *)queue;
@end