位置: 编程技术 - 正文

IOS为UNITY写插件/通信(unity iphone)

编辑:rootadmin

推荐整理分享IOS为UNITY写插件/通信(unity iphone),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:ios unity,unity插件编写,unity ui 插件,unity写app,unity 编辑器插件,unity 编辑器插件,unity ui 插件,ios嵌入unity,内容如对您有帮助,希望把文章链接给更多的朋友!

直接将.h .m 文件拷贝导Unity 》 Plugs>IOS 下,不要存在子文件夹;录音,百度SDK需要的库文件,在Unity导出IOS工程后需要再添加

#import <Foundation/Foundation.h>

#import "XHVoiceRecordHelper.h"

#import "BDVRFileRecognizer.h"

// Max record Time

#define kVoiceRecorderTotalTime .0

#define API_KEY @"1pMskN3kIS6G8ccU4TKXiZ"

#define SECRET_KEY @"fglBlnpKo6Q6VDXBD4efZGwZkW"

@interface VoiceRecordPlug :NSObject<MVoiceRecognitionClientDelegate>

//@property (nonatomic, strong) XHVoiceRecordHelper *voiceRecordHelper;

void startVoiceRecord();

void stopVoicRecord();

-(void)start;

&#;(void)autoInit;

@end

//

// VoiceRecordPlug.m

// VoiceRecord

//

// Created by bin.li on -3-3.

// Copyright (c) 年 bin.li. All rights reserved.

//

#import "VoiceRecordPlug.h"

static VoiceRecordPlug *plug =nil;

static XHVoiceRecordHelper *voiceRecordHelper;

@implementation VoiceRecordPlug

//- (id)init {

// NSLog(@"cute init..");

// self = [super init];

// plug = self;

// return self;

//}

&#;(void)autoInit

{

plug = [[VoiceRecordPlugalloc] init];

}

-(void)start

{

startVoiceRecord();

}

void startVoiceRecord()

{

if (!plug) {

[VoiceRecordPlug autoInit];

}

NSLog(@"start record");

NSString *recorderPath = nil;

recorderPath = [[NSStringalloc] initWithFormat:@"%@/Documents/",NSHomeDirectory()];

recorderPath = [recorderPath stringByAppendingFormat:@"MySound.wav"];

if (!voiceRecordHelper)

{

NSLog(@"voiceRecordHelper init..");

voiceRecordHelper = [[XHVoiceRecordHelperalloc] init];

voiceRecordHelper.maxRecordTime =;

voiceRecordHelper.maxTimeStopRecorderCompletion = ^{

[voiceRecordHelperstopRecordingWithStopRecorderCompletion:^{

NSLog(@"");

finishRecord();

}];

};

voiceRecordHelper.peakPowerForChannel = ^(float peakPowerForChannel) {

// weakSelf.voiceRecordHUD.peakPower = peakPowerForChannel;

};

}

[voiceRecordHelper startRecordingWithPath:recorderPath StartRecorderCompletion:^{///录音存储

NSLog(@"");

// finishRecord();

}];

}

void stopVoicRecord()

{

NSLog(@"stop record");

finishRecord();

}

void finishRecord()

{

NSLog(@"cute finishRecord()..");

NSString *recorderPath = nil;

recorderPath = [[NSStringalloc] initWithFormat:@"%@/Documents/",NSHomeDirectory()];

recorderPath = [recorderPath stringByAppendingFormat:@"MySound.wav"];

[voiceRecordHelper stopRecordingWithStopRecorderCompletion:^{

NSLog(@"begin connect baidu.");

[[BDVoiceRecognitionClientsharedInstance] setApiKey:API_KEYwithSecretKey:SECRET_KEY];

BDVRFileRecognizer *fileRecognizer = [[BDVRFileRecognizeralloc] initFileRecognizerWithFilePath:recorderPathsampleRate:property:EVoiceRecognitionPropertyInputdelegate:plug];//将语言文件上传百度识别

int status = [fileRecognizer startFileRecognition];

NSLog(@"begin connect baidu. status = %d",status);

// if (status != EVoiceRecognitionStartWorking) {

IOS为UNITY写插件/通信(unity iphone)

// return;

// }

}];

}

void playRecord()

{

// voiceRecordHelper

}

#pragma mark - MVoiceRecognitionClientDelegate 语音识别工作状态通知

- (void)VoiceRecognitionClientWorkStatus:(int) aStatus obj:(id)aObj

{

NSLog(@"enter.. VoiceRecognitionClientWorkStatus");

switch (aStatus) {

caseEVoiceRecognitionClientWorkStatusFinish:

{

// 该状态&#;表示语音识别服务器返回了最终结果,结果以数组的形式保存在 aObj对象中

// 接受到该消息时应当清空显示区域的文字以免重复

NSLog(@"EVoiceRecognitionClientWorkStatusFinish");

if ([[BDVoiceRecognitionClientsharedInstance] getRecognitionProperty] !=EVoiceRecognitionPropertyInput)

{

NSMutableArray *resultData = (NSMutableArray *)aObj;

NSMutableString *tmpString = [[NSMutableStringalloc] initWithString:@""];

// 获取识别候选词列表

for (int i=0; i<[resultDatacount]; i&#;&#;) {

[tmpString appendFormat:@"%@rn",[resultDataobjectAtIndex:i]]; }

NSLog(@"result: %@", tmpString);

} else {

NSMutableString *sentenceString = [[NSMutableStringalloc] initWithString:@""];

for (NSArray *resultin aObj)// 此时 aObj 是 array,result 也是 array

{

// 取每条候选结果的第一条,进行组合

// result 的元素是 dictionary,对应一个候选词和对应的可信度

NSDictionary *dic = [resultobjectAtIndex:0];

NSString *candidateWord = [[dicallKeys] objectAtIndex:0];

[sentenceString appendString:candidateWord];

}

NSLog(@"result: %@", sentenceString);

// UnitySendMessage("MainManager",uFun,[sentenceString UTF8String]);//与Unity通信 ,调用Unity 中的方法 uFun ,传参数 sentenceString

}

break;

}

caseEVoiceRecognitionClientWorkStatusFlushData:

{

// 该状态&#;表示服务器返回了中间结果,如果想要将中间结果展示给用户(形成连续上屏的效果),

// 可以利用与该状态同时返回的数据,每当接到新的该类消息应当清空显示区域的文字以免重复

NSMutableString *tmpString = [[NSMutableStringalloc] initWithString:@""];

[tmpString appendFormat:@"%@",[aObjobjectAtIndex:0]];

NSLog(@"%@",tmpString);

break;

}

caseEVoiceRecognitionClientWorkStatusError:

{

NSLog(@"EVoiceRecognitionClientWorkStatusError");

}

default:

break;

}

}

- (void)VoiceRecognitionClientErrorStatus:(int) aStatus subStatus:(int)aSubStatus

{

NSLog(@"VoiceRecognitionClientErrorStatus");

NSString *str = @"";

switch (aStatus) {

caseEVoiceRecognitionClientErrorStatusNoSpeech:

str = @"你怎么不说话呀!";

break;

caseEVoiceRecognitionClientErrorStatusShort:

str = @"你说话声音太短啦!";

break;

caseEVoiceRecognitionClientErrorStatusChangeNotAvailable:

str = @"录音设备不可用啊!";

break;

caseEVoiceRecognitionClientErrorStatusIntrerruption:

str = @"录音中断咯!";

break;

caseEVoiceRecognitionClientErrorNetWorkStatusUnusable:

str = @"网络不可用啦!";

break;

caseEVoiceRecognitionClientErrorNetWorkStatusError:

str = @"网络发生错误啦!";

break;

caseEVoiceRecognitionClientErrorNetWorkStatusTimeOut:

str = @"请求超时咯!";

break;

default:

str = @" 请认真说话呀! ";

break;

}

NSLog(@"error = %@",str);

// UnitySendMessage("MainManager",ufnc,[str UTF8String]);

}

@end

Protocol Buffers(Protobuf)开发者指南---概览 欢迎来到protocolbuffers的开发者指南文档,protocolbuffers是一个与编程语言无关‘、系统平台无关、可扩展的结构化数据序列化/反序列化工具,适用于

python标准库之SocketServer 转载自:

Unity PlayerPrefs.DeleteAll 无效以及 PlayerPrefs文件保存位置 DeleteAll无效检查下设置的公司名称和项目名称是否是中午!!!!!改成英文即可各平台保存路径OnMacOSXPlayerPrefsarestoredin~/Library/Preferencesfolder,inafilenamedu

标签: unity iphone

本文链接地址:https://www.jiuchutong.com/biancheng/383541.html 转载请保留说明!

上一篇:Unity NGUI——常见NGUI鼠标快捷操作(unity_jail)

下一篇:Protocol Buffers(Protobuf)开发者指南---概览

  • 出口货物退(免)税管理办法
  • 公司租赁个人车辆税率是多少
  • 生产型企业直接进口产品是否可直接出口
  • 运输费计入什么科目分录
  • 机动车发票怎么入账
  • 发票校验码看不清怎样查真伪
  • 建筑公司核定征收所得税怎么算
  • 拆迁补偿款上交财政
  • 什么是前期差错
  • 固定资产未验收投入使用
  • 咨询案例模板
  • 税务是如何处理违章的
  • 企业法人信息变更
  • 退役士兵增值税优惠申报方法
  • 金税盘初始密码忘记了怎么办
  • 附加税有哪些税种
  • 党建工作经费计提比例
  • 280元航天使用费多少钱
  • 生活补贴和节日补贴区别
  • 分期付款购买商品房后续没钱还怎么办
  • 境外承包工程出口货物能否办理退税?
  • 营改增建筑业
  • 非关联企业无偿拆借资金企业所得税
  • 民间非营利组织会计制度会计科目
  • 投资者减除费用30000
  • 默认网关不可用修复后过一会又不好使了
  • 增值税附税的计算公式
  • php解析xml文件
  • 股权折价转让
  • 营改增前甲供材施工企业如何缴纳企业所得税
  • 前端登录退出怎么操作
  • 辞退员工补偿标准是n+1还是2n
  • 短期借款利息的核算不可能涉及的账户是
  • 报废车怎么走流程
  • php 加密
  • 详解Yii2高级版引入bootstrap.js的一个办法
  • 前端项目性能优势怎么写
  • web自动化测试项目
  • is-l命令
  • 专票电话号码不对有影响吗
  • 退税申报系统里出货明细金额少0.1会比对报关单金额吗
  • 引导式申报带出来的开票额与金税盘显示的不一致
  • 帝国cms怎么用
  • 怎么样去掉
  • javascript基础笔记
  • 企业年报股东出资信息
  • 法人买社保又不发工资怎么做账
  • 赠送礼品怎么入账
  • 企业购买国债逆回购怎么操作
  • 没有销售怎么写总结
  • 坐车时的保险费怎么算
  • 当期应纳税额是什么意思
  • 工资薪金个人所得税怎么申报
  • 小规模纳税人中标一般计税
  • windows10已经阻止此软件
  • win7命令提示符怎么打开
  • linuxsu命令作用
  • dds使用方法
  • ksysslim.exe是什么
  • win7系统怎么禁用win键
  • 磁盘修复完成以后怎么办
  • NGUI字体图集导致Label文字破碎的BUG以及解决方案
  • uisrollview
  • javascript HTML5 canvas实现打砖块游戏
  • vxlan配置实例详解
  • jquery自定义事件
  • 修改cmd中显示的用户名!
  • 泛型类泛型接口泛型方法
  • python asyncio
  • android listview数据动态加载
  • android开发从入门到精通(项目案例版)
  • javascript原生函数的源代码
  • 国家税务总局一个月多少钱
  • 发票被暂停了严重吗
  • 车船税单独交行吗
  • 房山税收减免政策文件
  • 完税证明在哪里查询打印
  • 四川税控
  • 出口货物计算公式
  • 公司财务专用章的用途
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设