公司里提出一个需求,需要接讯飞的语音识别和语音合成SDK 。对于Android还好网上有很多的例子。对照着接SDK就好。但是IOS的网上的例子不是太多,尤其是对于小晴这种不会儿玩Xcode的unity程序员来说,更是难上加难。还好我看到阿黄的一片文章http://lib.csdn.net/article/unity3d/58020?knid=1283,这才看到了希望。看到这篇文章学会了接语音识别的SDK。然后照葫芦画瓢把语音合成的也接上了。
语音识别的就不多说了,按照阿黄的写就可以,可能会出现一个小问题就是,内容显示一下就没了。其实这个好解决 ,在Unity那边判断一下不为空的情况下把内容记录下来就OK了。
我还是把代码贴出来吧!
//
// ViewController.h
// Test4
//
// Created by Xiyue Game on 17/8/21.
// Copyright © 2017年 Xiyue Game. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "iflyMSC/IFlyMSC.h"
#import "Reachability.h"
#import "iflyMSC/IFlySpeechSynthesizerDelegate.h"
//引入语音合成类
@class IFlySpeechSynthesizer;
@class IFlyDataUploader;
@interface ViewController : UIViewController<IFlySpeechRecognizerDelegate,IFlySpeechSynthesizerDelegate,IFlyRecognizerViewDelegate,UIActionSheetDelegate>
@property (nonatomic, strong) IFlySpeechRecognizer *iFlySpeechRecognizer;//不带界面的识别对象
@property (nonatomic, strong) NSString * result;
@property (nonatomic, assign) BOOL isCanceled;
//声明语音合成的对象
@property (nonatomic, strong) IFlySpeechSynthesizer *iFlySpeechSynthesizer;
+ (ViewController*) instance;
-(void) isConnectionAvailable;//判断是否有网络
void _startup(void);
@end
//
// ViewController.m
// Test4
//
// Created by Xiyue Game on 17/8/21.
// Copyright © 2017年 Xiyue Game. All rights reserved.
//
#import "ViewController.h"
#import "iflyMSC/IFlyMSC.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 在加载视图后,通常从笔尖进行任何其他设置。
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
//处理可以重新创建的任何资源。
}
static ViewController* gameMgr=nil;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
+ (ViewController*) instance
{
if (gameMgr==nil)
{
gameMgr=[[ViewController alloc]init];
}
return gameMgr;
}
-(void)initRecognizer
{
NSLog(@"%s",__func__);