位置: 编程技术 - 正文

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)开发者指南---概览

  • 企业所得税会计分录怎么做
  • 不得从销项税中抵扣的进项税大白话
  • 合伙律师事务所的合伙人必须是
  • 国外酒店打印的住宿单可以入账吗
  • 分包从属总包选择简易计税可以吗
  • 固定资产清理的金额怎么算
  • 建筑工地加油计入什么科目
  • 管理费用劳保费属于
  • 营业税金及附加包括增值税吗
  • 处置固定资产账务处理例题
  • 营改增前土地增值税的计算方法
  • 私营独资企业可以变更法人吗
  • 可转换可赎回债券
  • 个体工商户生产经营所得税率
  • 小规模纳税人购买原材料会计分录
  • 其他应付款在现金流量表中应该填哪里
  • 取得抵债资产的方式主要有以下几种
  • 净利润含不含所得税
  • 未达起征点销售额和小微企业免税销售额
  • 增值税发票查验平台官网网络异常
  • 增值税纳税义务人
  • 企业计提的安全生产费用年末应如何处理
  • 自制材料入库计划成本
  • 年初未交增值税借方怎么处理
  • 公司与客户合作协议范本
  • 一般纳税人增值税申报表怎么填写
  • 医疗机构医疗服务自查报告怎么写
  • 工厂返费能拿到吗
  • php语法和常用的函数
  • 今夕七夕
  • 塔卡夫斯基镜子
  • htmlcssjavascript网页制作
  • 微信小程序如何删除
  • Python中tkinter的 Variable类
  • 递延所得税资产和所得税费用的关系
  • 小规模纳税人抵税是普票还是专票
  • 个体工商户开税户
  • 车辆保险费怎么入账
  • 怎么开电子专用增值税发票
  • 权责发生制 会计
  • 小规模当月开普票作废流程
  • 土地使用权的使用是什么意思
  • 存货周转率特别高说明什么
  • 单位食堂账目
  • 五险一金没有金
  • 办公楼开始建造前专门借款的利息费用
  • 赠送样品视同销售增值税该怎么做账务处理呢?
  • 超期应收款管控
  • 福利费的概念是指
  • 外购商品科目设置
  • 企业计提增值税怎么写
  • 收到商业承兑汇票的会计分录
  • 房地产项目企业
  • sql自定义变量
  • win8系统如何安装软件
  • win10edge浏览器默认主页网址
  • windows怎样设置
  • xp怎么安装iis
  • debian linux教程
  • cocos2dx怎么打开
  • extjs DataReader、JsonReader、XmlReader的构造方法
  • Android开源ui框架
  • cocos code ide 1.0.0 RC0 使用教程
  • qt::windowtype
  • 深入领悟六个必须坚持
  • unity图集
  • [android那些事] linux 下android源码编译(国内被墙方案)
  • shell 整数赋值
  • python ping ip地址
  • 用jquerymobile案例
  • python toad
  • js所有知识点
  • 四川国税局普通发票查询?
  • 税务上征信
  • 契税完税证明怎么补打
  • 装卸搬运费属于
  • 社保工资申报错了可以重新申请吗
  • 武汉市房产证契税 2023
  • 土地增值税分期清算条件?
  • 国家税务北京税务局
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设