位置: 编程技术 - 正文

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

  • 生产成本年末转入什么科目
  • 退税是什么科目的
  • 企业所得税如何申报操作
  • 什么是纳税义务人,在理解这一观念时应注意哪些问题
  • 全年一次性奖金计税方式2023
  • 车费报销计入什么费用
  • 什么情况下视同销售
  • 可转换债券含义
  • 事假扣薪
  • 可以用来办理贴现的票据
  • 小规模建筑公司预缴增值税
  • 往年的制造费用怎么算
  • 一般纳税人税控维护费怎么填报
  • 小规模纳税人零申报是每季度报吗
  • 发生应收账款如何入账可避税
  • 视同销售可以抵扣销项税吗?
  • 食用油从商业流入的原因
  • 简易计税的分包款可以留到下期抵扣吗
  • 免交的增值税怎么退
  • 企业一般每个月几号上工伤保险
  • 税务实名制法人和财务负责人可以是同一人吗?
  • 打印机第一行未赋码
  • 如何利用成套消费品进行纳税筹划
  • 销项负数票需要把之前的票退回吗
  • 电子发票截图可以吗
  • 合作保证金规定
  • 生产型企业进口退税政策
  • win7系统中如何让未响应的程序继续运行
  • 水利基金返还分录怎么写
  • 在win7系统中文件属性有哪些
  • 为什么无形资产是非流动资产
  • 使用Huagepage和PGO来提升PHP7的执行性能
  • 吃鸡到底用什么显卡性价比最高?
  • 利润总额为负还交所得税吗
  • php中session什么意思
  • 深入理解ts
  • windowsserver2019产品密钥
  • domain codomain range
  • 如何更改telnet端口
  • 福利费计入科目
  • 企业补助怎么做会计分录
  • 社会团体会费票据查询
  • 公司一年的账目怎样算
  • 物业管理企业会计核算的特点如何?
  • 委托银行贷款利息发票谁提供
  • 用负数表示的例子
  • 财付通支付的优缺点
  • 什么叫递延收益和其他收益
  • 职工辞退福利是否要申报个税
  • 银行转存款怎么办
  • 一般纳税人资格证书怎么查询
  • 未分配利润核销不良贷款
  • 暂估收不到发票,怎么处理
  • 开出发票后直接做账吗?
  • 核销预收账款是否需要计提增值税
  • 科目汇总表里面要填累计折旧吗
  • 备份数据还原不了怎么办
  • 在Vista、Windows7下玩英雄无敌3绿色版
  • centos yum报错
  • win7 重装系统
  • 怎么用苹果电脑打印照片
  • 如何设置无线网密码
  • pln是什么文件
  • win7为什么打不开原神
  • 微软7月补丁
  • win8不能安装软件
  • windows10 禁用u盘
  • nodejs项目开发
  • unity怎么用
  • vue路由跳转的钩子函数什么时候会用到
  • ip地址编址方法
  • java stringapi
  • 超清晰的壁纸
  • android 底部选择菜单
  • javascript电商项目
  • jquery 选择
  • 公司税务电子发票怎么开
  • 小规模纳税人需要进项票吗
  • 梦幻西游新区绿色通道多少钱
  • 浙江税务局网络发票页无法打字
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设