官方文档:http://www.xfyun.cn/doccenter/iOS

目前开放的服务:



准备工作

  • 需要到讯飞官网注册一个开发账号,注册后登录并创建一个新的应用,添加需要的服务(语音听写、语音合成等等),应用创建后可以得到一个Appid,这个要在开发中初始化讯飞语音应用中用到。

  • 工程中找到Targets->Build Phases->Link Binary With Libraries,添加下面的库,注意iflyMSC.framework下载后一定要保证导入到工程目录下,而不能只是个路径引用否则会报错。另外需要在Build Settings的Build Options中关闭BitCode。

  • 在需要的地方引入讯飞语音库头文件,当然可以根据需要只引入某种服务的头文件

#import <iflyMSC/iflyMSC.h> // 引入讯飞语音库
#ifndef MSC_IFlyMSC_h
#define MSC_IFlyMSC_h#import "IFlyAudioSession.h"
#import "IFlyContact.h"
#import "IFlyDataUploader.h"
#import "IFlyDebugLog.h"
#import "IFlyISVDelegate.h"
#import "IFlyISVRecognizer.h"
#import "IFlyRecognizerView.h"
#import "IFlyRecognizerViewDelegate.h"
#import "IFlyResourceUtil.h"
#import "IFlySetting.h"
#import "IFlySpeechConstant.h"
#import "IFlySpeechError.h"
#import "IFlySpeechEvaluator.h"
#import "IFlySpeechEvaluatorDelegate.h"
#import "IFlySpeechEvent.h"
#import "IFlySpeechRecognizer.h"
#import "IFlySpeechRecognizerDelegate.h"
#import "IFlySpeechSynthesizer.h"
#import "IFlySpeechSynthesizerDelegate.h"
#import "IFlySpeechUnderstander.h"
#import "IFlySpeechUtility.h"
#import "IFlyTextUnderstander.h"
#import "IFlyUserWords.h"
#import "IFlyPcmRecorder.h"
#import "IFlyVoiceWakeuper.h"
#import "IFlyVoiceWakeuperDelegate.h"#endif
  • 使用Appid初始化讯飞应用,在应用启动的地方使用Appid初始化语音应用,这里放在了AppDelegate应用代理文件下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",@"587f6174"];[IFlySpeechUtility createUtility:initString];return YES;
}

语音合成和语音测评示例

这里因为要使用语音合成和测评功能所以先测试了这两个,其他的类似,可参考官方文档:

  • 应用启动后会有‘小燕’的声音读出:”Hello, this is xiaoyan!”
  • 应用启动后测评”Today is a sunny day!”的发音

先要使用Appid初始化:

//
//  ViewController.m
//  XFDemo
//
//  Created by Xinhou Jiang on 4/3/17.
//  Copyright © 2017年 Xinhou Jiang. All rights reserved.
//#import "ViewController.h"
#import <iflyMSC/iflyMSC.h> // 引入讯飞语音库@interface ViewController ()<IFlySpeechSynthesizerDelegate,IFlySpeechEvaluatorDelegate> { // 语音代理协议}
@property (nonatomic, strong)IFlySpeechSynthesizer *iFlySpeechSynthesizer;    // 定义语音合成对象
@property (nonatomic, strong)IFlySpeechEvaluator *iFlySpeechEvaluator;        // 定义语音测评对象@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 1.开始合成说话//[self.iFlySpeechSynthesizer startSpeaking:@"Hello, this is xiaoyan!"];// 2.开始语音测评NSData *textData = [@"Today is a sunny day!" dataUsingEncoding:NSUTF8StringEncoding];[self.iFlySpeechEvaluator startListening:textData params:nil];
}#pragma -mark 语音合成
/*** 懒加载getter方法*/
- (IFlySpeechSynthesizer *)iFlySpeechSynthesizer {if(!_iFlySpeechSynthesizer) {// 初始化语音合成_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];_iFlySpeechSynthesizer.delegate = self;// 语速【0-100】[_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant SPEED]];// 音量【0-100】[_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant VOLUME]];// 发音人【小燕:xiaoyan;小宇:xiaoyu;凯瑟琳:catherine;亨利:henry;玛丽:vimary;小研:vixy;小琪:vixq;小峰:vixf;小梅:vixl;小莉:vixq;小蓉(四川话):vixr;小芸:vixyun;小坤:vixk;小强:vixqa;小莹:vixying;小新:vixx;楠楠:vinn;老孙:vils】[_iFlySpeechSynthesizer setParameter:@"xiaoyan" forKey:[IFlySpeechConstant VOICE_NAME]];// 音频采样率【8000或16000】[_iFlySpeechSynthesizer setParameter:@"8000" forKey:[IFlySpeechConstant SAMPLE_RATE]];// 保存音频路径(默认在Document目录下)[_iFlySpeechSynthesizer setParameter:@"tts.pcm" forKey:[IFlySpeechConstant TTS_AUDIO_PATH]];}return _iFlySpeechSynthesizer;
}/*** 合成结束*/
- (void)onCompleted:(IFlySpeechError *)error {NSLog(@"合成结束!");
}/*** 合成开始*/
- (void)onSpeakBegin {NSLog(@"合成开始!");
}/*** 合成缓冲进度【0-100】*/
- (void)onBufferProgress:(int)progress message:(NSString *)msg {NSLog(@"合成缓冲进度:%d/100",progress);
}/*** 合成播放进度【0-100】*/
- (void)onSpeakProgress:(int)progress beginPos:(int)beginPos endPos:(int)endPos {NSLog(@"合成播放进度:%d/100",progress);
}#pragma -mark 语音测评
/*** 懒加载getter方法*/
- (IFlySpeechEvaluator *)iFlySpeechEvaluator {if (!_iFlySpeechEvaluator) {// 初始化语音测评_iFlySpeechEvaluator = [IFlySpeechEvaluator sharedInstance];_iFlySpeechEvaluator.delegate = self;// 设置测评语种【中文:zh_cn,中文台湾:zh_tw,美英:en_us】[_iFlySpeechEvaluator setParameter:@"en_us" forKey:[IFlySpeechConstant LANGUAGE]];// 设置测评题型【read_syllable(英文评测不支持):单字;read_word:词语;read_sentence:句子;read_chapter(待开放):篇章】[_iFlySpeechEvaluator setParameter:@"read_sentence" forKey:[IFlySpeechConstant ISE_CATEGORY]];// 设置试题编码类型[_iFlySpeechEvaluator setParameter:@"utf-8" forKey:[IFlySpeechConstant TEXT_ENCODING]];// 设置前、后端点超时【0-10000(单位ms)】[_iFlySpeechEvaluator setParameter:@"10000" forKey:[IFlySpeechConstant VAD_BOS]]; // 默认5000ms[_iFlySpeechEvaluator setParameter:@"1000" forKey:[IFlySpeechConstant VAD_EOS]]; // 默认1800ms// 设置录音超时,设置成-1则无超时限制(单位:ms,默认30000)[_iFlySpeechEvaluator setParameter:@"5000" forKey:[IFlySpeechConstant SPEECH_TIMEOUT]];// 设置结果等级,不同等级对应不同的详细程度【complete:完整 ;plain:简单】[_iFlySpeechEvaluator setParameter:@"" forKey:[IFlySpeechConstant ISE_RESULT_LEVEL]];}return _iFlySpeechEvaluator;
}/*** 开始说话回调*/
- (void)onBeginOfSpeech {NSLog(@"开始说话...");
}/*** 说话结束回调*/
- (void)onEndOfSpeech {NSLog(@"说话结束...");
}/*** 测评结果*/
- (void)onResults:(NSData *)results isLast:(BOOL)isLast {NSLog(@"测评结果:%@",results);
}/*** 出错回调*/
- (void)onError:(IFlySpeechError *)errorCode {NSLog(@"语音测评出错:%@",errorCode);
}/*** 音量变化回调*/
- (void)onVolumeChanged:(int)volume buffer:(NSData *)buffer {NSLog(@"音量变化...");
}/*** 取消*/
- (void)onCancel {NSLog(@"正在取消...");
}@end

Demo 下载:https://github.com/jiangxh1992/XFSpeechDemo

【Demo】iOS平台上的讯飞语音识别语音合成开发相关推荐

  1. 嵌入式openwrt平台(mt7688)上使用讯飞语音服务

    还记得第一次接触嵌入式开发,boss拿着一块widora的mt7688板子让我去开发openwrt环境下的使用讯飞语音技术的应用.我的天啊,我第一次接触,这是什么东西.因此,我这个新手走了不少弯路,但 ...

  2. 讯飞语音识别demo实现

    最近看了看百度语音和讯飞语音识别的实现,吐个槽,他们的官方文档是真的写得垃圾,可能是我技术不到位, 反正我是很难看懂的,不吐槽了,先上实现 讯飞的官方文档 https://doc.xfyun.cn/m ...

  3. Flutter版讯飞语音识别demo

    xf_demo是根据科大讯飞语音听写的WebAPI编写的Flutter版demo 官方文档地址:https://www.xfyun.cn/doc/asr/voicedictation/API.html ...

  4. 腾讯、百度、讯飞 语音识别

    一.腾讯语音识别-一句话语音识别 1.账号申请 (1)搜索腾讯云官网 https://cloud.tencent.com/?fromSource=gwzcw.2212127.2212127.22121 ...

  5. 语音识别技术原理是什么 讯飞语音识别技术特点介绍【详解】

    语音识别技术原理简介 自动语音识别技术(Auto Speech Recognize,简称ASR)所要解决的问题是让计算机能够"听懂"人类的语音,将语音中包含的文字信息"提 ...

  6. 讯飞语音识别配置笔记

    不久前开发过讯飞语音识别和小程序结合的系统,发表了一篇配置记录,有一些同学问一下问题,我再把我但是自己做的另外一篇记录发出来,给需要的同行参考一下.上一篇文章的地址:http://blog.csdn. ...

  7. 讯飞语音识别和唤醒开发示例

    讯飞语音识别和唤醒开发示例 最近需要用到讯飞的语音识别和语音唤醒的功能,就对这方面进行了一下简单研究. 本文帮助大家简单入门,并且提供几个代码示例给大家参考. 讯飞开发者网址:https://www. ...

  8. unity通过WebAPI连接Websocket实现讯飞语音识别与合成。

    下载地址:https://download.csdn.net/download/qq_39735878/12447473 unity写的讯飞语音识别合成与评测功能,走的是webapi,连接讯飞WebS ...

  9. 【幻灯片分享】iOS平台上开发音视频处理 | 盛大微酷 赵志猛 | iOS DevCamp

    专业视频处理算法在移动开发中的优化:<iOS平台上开发音视频处理>| 盛大微酷赵志猛 | iOS DevCamp 主题简介:视频处理技术,已经在专业设备上得到了几十年的发展.但是这些处理方 ...

最新文章

  1. centos把mysql移到数据盘_Centos转移Mysql的数据位置
  2. WebGL——osg框架学习一
  3. 如何获取元素在父级div里的位置_关于元素的浮动你了解多少
  4. fprintf 和 perror 的理解1
  5. Fiddler (二) : Script 的 用法
  6. java override 访问权限_java基础之——访问修饰符(private/default/protected/public)
  7. vue amp; nuxt 博客网站
  8. 2020计算机科学第五轮评估,2019-2020全国计算机专业大学排名
  9. Strust2的sx:datetimepicker限制日期选择
  10. 简述html文件的基本标记组成_HTML是什么呢?
  11. 从16位到32位再到64位,为何16年过去,依然没有128位系统出现?
  12. VB 几种打开文本文件速度对比
  13. mysql 数据库军规_用尽洪荒之力整理的Mysql数据库32条军规(转)
  14. c++ pdflib 中文乱码解决思路
  15. Access操作必须使用一个可更新的查询
  16. Java实现微信统一服务消息
  17. 5V输入升压14.4V四串磷酸铁锂电池充电芯片板 ,12.8V-32号电路板
  18. MacBook上不显示外接硬盘未装载解决方法
  19. PMS进化论:回顾过去才能更好地看向未来!
  20. 遇见Laravel Migrations的migrate与rollback

热门文章

  1. YTU OJ 2775: 字母的争论
  2. C:\Users\Kelly\AppData\Roaming\npm-cache\_logs\2019-03-24T08_17_24_284Z-debug.log
  3. Java集合之Map集合
  4. 多商户商城子商户推广员功能说明介绍
  5. 腾讯内容平台系统的架构实践
  6. 广告变现数据分析,提高媒体广告变现效果的关键指标!
  7. 普中51单片机学习日记-点亮LED
  8. [龙讯4号]龙芯图谋你的客厅
  9. 书评--提升软件质量的必经之路
  10. 4Vs营销理论(转载 )