iOS开发讯飞语音的集成
Posted jianbo_iOS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发讯飞语音的集成相关的知识,希望对你有一定的参考价值。
1.进入官网注册账号,登陆,注册,应用。
2,下载sdk 导入系统库。
3,关闭bitcode
4,初始化讯飞语音。
NSString * initString = [[NSString alloc] initWithFormat:@"appid=%@",@"56fb34f4"];
[IFlySpeechUtility createUtility:initString];
5.集成代码
#import <UIKit/UIKit.h>
#import "iflyMSC/IFlySpeechConstant.h"
#import "iflyMSC/IFlySpeechSynthesizer.h"
#import "iflyMSC/IFlySpeechSynthesizerDelegate.h"
@interface ViewController : UIViewController<IFlySpeechSynthesizerDelegate>
{
IFlySpeechSynthesizer * _iFlySpeechSynthesizer;
}
@end
#import "ViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.textField.delegate = self;
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance]; _iFlySpeechSynthesizer.delegate =
self;
//2.设置合成参数
//设置在线工作方式
[_iFlySpeechSynthesizer setParameter:[IFlySpeechConstant TYPE_CLOUD]
forKey:[IFlySpeechConstant ENGINE_TYPE]];
//音量,取值范围 0~100
[_iFlySpeechSynthesizer setParameter:@"50" forKey: [IFlySpeechConstant VOLUME]];
//发音人,默认为”xiaoyan”,可以设置的参数列表可参考“合成发音人列表” [_iFlySpeechSynthesizer setParameter:@" xiaoyan " forKey: [IFlySpeechConstant VOICE_NAME]]; //保存合成文件名,如不再需要,设置设置为nil或者为空表示取消,默认目录位于 library/cache下
[_iFlySpeechSynthesizer setParameter:@" tts.pcm" forKey: [IFlySpeechConstant TTS_AUDIO_PATH]];
[_iFlySpeechSynthesizer setParameter:@"" forKey:[IFlySpeechConstant VOICE_NAME]];
NSString * str = [IFlySpeechConstant VOICE_NAME];
NSLog(@"%@",str);
}
- (IBAction)voiceAction:(id)sender {
[self.textField resignFirstResponder];
[_iFlySpeechSynthesizer startSpeaking: self.textField.text];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.textField resignFirstResponder];
}
- (IBAction)endVoicePlay:(id)sender {
[_iFlySpeechSynthesizer pauseSpeaking];
}
- (IBAction)resumePlay:(id)sender {
[_iFlySpeechSynthesizer resumeSpeaking];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self voiceAction:nil];
return YES;
}
//结束代理
- (void) onCompleted:(IFlySpeechError *) error{
NSLog(@"结束");
}
//合成开始
- (void) onSpeakBegin{
NSLog(@"合成开始");
}
//合成缓冲进度
- (void) onBufferProgress:(int) progress message:(NSString *)msg
{
}
//合成播放进度
- (void) onSpeakProgress:(int) progress{
}
以上是关于iOS开发讯飞语音的集成的主要内容,如果未能解决你的问题,请参考以下文章