一、简单说明

   (1)

在iOS7之前,想要实现语音播报文字内容,可能需要第三方资源库来实现。现在在iOS7上,系统为我们提供了语音播报文字的功能,我们不仅可以播报英语内容,也可以播报汉语文字

实现TTS主要依赖AVSpeechSynthesizer,AVSpeechUtterance,AVSpeechSynthesisVoice,要使用这些类必须先加入

AVFoundation框架:

AVSpeechSynthesisVoice:用来配置发音,支持的发音非常多.个人感觉台湾发音最好听~通过调用

[AVSpeechSynthesisVoicespeechVoices]类方法可用看到支持的发音种类;

AVSpeechUtterance:这个类就是用来将字符串合成为语音对象提供给AVSpeechSynthesizer来播放,这个类还有一些

实例方法用来控制语速,音调等等。。

实现代码:

     TXSoundPlayer.h文件代码:

 1 //  Created by 鑫 on 14/12/23.
 2 //  Copyright (c) 2014年 梁镋鑫. All rights reserved.
 3 //
 4 
 5 #import <Foundation/Foundation.h>
 6 #import <AVFoundation/AVFoundation.h>
 7 
 8 @interface TXSoundPlayer : NSObject
 9 {
10     NSMutableDictionary* soundSet;  //声音设置
11     NSString* path;  //配置文件路径
12 }
13 
14 @property(nonatomic,assign)float rate;   //语速
15 @property(nonatomic,assign)float volume; //音量
16 @property(nonatomic,assign)float pitchMultiplier;  //音调
17 @property(nonatomic,assign)BOOL autoPlay;  //自动播放
18 
19 
20 +(TXSoundPlayer*)soundPlayerInstance;
21 
22 -(void)play:(NSString*)text;
23 
24 -(void)setDefault;
25 
26 -(void)writeSoundSet;
27 
28 @end
View Code

相关文章:

  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-11-29
  • 2021-04-05
  • 2022-12-23
  • 2021-07-03
  • 2022-01-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-08-28
相关资源
相似解决方案