AVSpeech 的基础知识(AVFoundation)

speech

AVSpeechUtterance 语音话语
包括: 语种(eg:zh-CN)、内容(文字)
@property(nonatomic) NSTimeInterval preUtteranceDelay;    // Default is 0.0   读一段话之前的停顿
@property(nonatomic) NSTimeInterval postUtteranceDelay;   // Default is 0.0  读完一段后的停顿时间

@property(nonatomic) float rate;// Values are pinned between AVSpeechUtteranceMinimumSpeechRate and AVSpeechUtteranceMaximumSpeechRate.
@property(nonatomic) float pitchMultiplier;  // [0.5 - 2] Default = 1 音高
@property(nonatomic) float volume;           // [0-1] Default = 1

初始化
+ (instancetype)speechUtteranceWithString:(NSString *)string;
+ (instancetype)speechUtteranceWithAttributedString:(NSAttributedString *)string API_AVAILABLE(ios(10.0), watchos(3.0), tvos(10.0));
- (instancetype)initWithString:(NSString *)string;
- (instancetype)initWithAttributedString:(NSAttributedString *)string API_AVAILABLE(ios(10.0), watchos(3.0), tvos(10.0));
创建发言对象通过内容


@property(nonatomic, readonly) NSString *speechString;
@property(nonatomic, readonly) NSAttributedString *attributedSpeechString API_AVAILABLE(ios(10.0), watchos(3.0), tvos(10.0));
应该是10 之后-支持了一些东西;

@property(nonatomic, retain, nullable) AVSpeechSynthesisVoice *voice;
声明为retain ,其实应该对应的就是一个位置的结构体类似;

语种的设置
@interface AVSpeechSynthesisVoice : NSObject<NSSecureCoding>

+ (NSArray<AVSpeechSynthesisVoice *> *)speechVoices; // 所有的饿支持的语种
+ (NSString *)currentLanguageCode; // 语种的代码

初始化 (通过语种代码)
+ (nullable AVSpeechSynthesisVoice *)voiceWithLanguage:(nullable NSString *)languageCode;

这个方式也是通过identifier来进行初始化; (应该是可以进行自定义一些内容)
+ (nullable AVSpeechSynthesisVoice *)voiceWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(9_0);

读取的属性
@property(nonatomic, readonly) NSString *language;
@property(nonatomic, readonly) NSString *identifier NS_AVAILABLE_IOS(9_0);
@property(nonatomic, readonly) NSString *name NS_AVAILABLE_IOS(9_0);
@property(nonatomic, readonly) AVSpeechSynthesisVoiceQuality quality NS_AVAILABLE_IOS(9_0);

@end

AVSpeechSynthesizer 语音合成器
@property(nonatomic, weak, nullable) id<AVSpeechSynthesizerDelegate> delegate; 代理
@property(nonatomic, readonly, getter=isSpeaking) BOOL speaking;  // 进行
@property(nonatomic, readonly, getter=isPaused) BOOL paused; // 暂停

- (void)speakUtterance:(AVSpeechUtterance *)utterance;
播放语音

停止播放语音的边界,打断当前的语音和清除队列;
/* Call stopSpeakingAtBoundary: to interrupt current speech and clear the queue. */
- (BOOL)stopSpeakingAtBoundary:(AVSpeechBoundary)boundary;
- (BOOL)pauseSpeakingAtBoundary:(AVSpeechBoundary)boundary;
- (BOOL)continueSpeaking;

typedef NS_ENUM(NSInteger, AVSpeechBoundary) {
    AVSpeechBoundaryImmediate, //立刻停止
    AVSpeechBoundaryWord // 读完最后一个字停止
} NS_ENUM_AVAILABLE_IOS(7_0);

@property(nonatomic, retain, nullable) NSArray<AVAudioSessionChannelDescription *> *outputChannels API_AVAILABLE(ios(10.0), watchos(3.0), tvos(10.0));
指定输出的渠道,这里是audiochannel 在当前的audio 的rote上;复制到指定的渠道里面
常量

个人测试的值是: 最小是0 ,最大是1.0 ,默认是0.5

觉得这里不够清楚,可以看官方文档,这里是对官方文档的一些理解

使用例子请看:
http://www.jianshu.com/p/00dac8e040d5

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,930评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,845评论 18 139
  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,522评论 7 249
  • 2017年7月3日 晴 吃了一半的桃子 也发黄了 一半的粗燥右手 麻木静止了 写了一半的日记 内容干枯了 现在意识...
    鲜栗子阅读 198评论 1 2
  • 冬末春至 骤然降温 风微凉 心稍暖 太阳躲在云里 云里藏着阳光 凋零的花瓣 泥土里泛着余香 坚挺的枝干 紫禁花绽放...
    BobBruno阅读 436评论 2 51