当前位置:首页 > 通信资讯 > 正文

微信语音 ios(ios 语音)

微信只能开发平台http://pr.weixin.qq.com/,里面包含了微信语音和图像,集成很简单,下载方demo后会有个文档,按照流程来(因为它只提供了真机的.a文件,所以只能用真机哦,不然会报错)

先用个有ui界面的sdk

1.装上sdk,引入相关包

微信语音 ios(ios 语音)

2.设置 build settings

c++ standard library: libstdc++ 或 compiler default

compile sources as: objective-c++ 或 将使用 sdk 的文件扩展名改为.mm

微信语音 ios(ios 语音)

随便把一个文件后缀改成.mm不然会报错

3.添加代码

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #import "customnewviewcontrol.h" #import "wxspeechrecognizerwithui.h" @interface customnewviewcontrol ()<wxvoicewithuidelegate> { wxspeechrecognizerwithui *_wxssui; __weak iboutlet uilabel *label; } @property (weak, nonatomic) iboutlet uibutton *button; @end @implementation customnewviewcontrol - (void)viewdidload { [super viewdidload]; _wxssui = [[wxspeechrecognizerwithui alloc] initwithdelegate:self anduserkey:@"bfcecacabcbeaecdcbca"]; } //点击事件 - (ibaction)buttonpressed:(uibutton *)sender { label.text = @""; [_wxssui showandstart]; } //代理 wxvoicewithuidelegate - (void)voiceinputresultarray:(nsarray *)array{ wxvoiceresult *result=[array objectatindex:]; [label settext:result.text]; }

无ui界面的sdk也差不多

注意:使用无界面ui需要遵守以下规则

微信语音开放平台免费为你的应用提供语音识别服务,你可以根据自己的风格自由制定 ui,但需在语音采集识别的窗口正确、完整的标注“powered by 微信智能”或“语音技术由 微信智能提供”的字样。参考如下弹窗:

微信语音 ios(ios 语音)

集成和上面一样,就不再重复

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 // // viewcontroller.m // weixinyuyinwuui // // created by apple on //. // copyright (c) 年 tqh. all rights reserved. // #import "viewcontroller.h" #import "wxvoicesdk.h" @interface viewcontroller ()<wxvoicedelegate> @property (weak, nonatomic) iboutlet uilabel *label; @property (weak, nonatomic) iboutlet uibutton *button; @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; // sdk wxvoicesdk *speechrecognizer = [wxvoicesdk sharedwxvoice]; //可选设置 speechrecognizer.siltime = .f; //必选设置 speechrecognizer.delegate = self; [speechrecognizer setuserkey:@"bfcecacabcbeaecdcbca"]; } #pragma mark -----------wxvoicedelegate------------ - (void)voiceinputresultarray:(nsarray *)array{ //一旦此方法被回调,array一定会有一个值,所以else的情况不会发生,但写了会更有安全感的 if (array && array.count>) { wxvoiceresult *result=[array objectatindex:]; _label.text = result.text; }else{ _label.text = @""; } } - (void)voiceinputmakeerror:(nsinteger)errorcode{ _label.text = [nsstring stringwithformat:@"错误:%ld",(long)errorcode]; } - (void)voiceinputvolumn:(float)volumn{ // [_speechrecognizerview setvolumn:volumn]; } - (void)voiceinputwaitforresult{ // [_speechrecognizerview finishrecorder]; } - (void)voiceinputdidcancel{ // [_speechrecognizerview didcancel]; } #pragma mark - 点击事件 - (ibaction)buttonpressed:(uibutton *)sender { sender.selected = !sender.selected; if (sender.selected) { _label.text = @"录音中..."; [[wxvoicesdk sharedwxvoice] startonce]; [_button settitle:@"完成" forstate:uicontrolstatenormal]; }else { [[wxvoicesdk sharedwxvoice] finish]; [_button settitle:@"录音" forstate:uicontrolstatenormal]; } } - (ibaction)cancelbuttonpressed:(uibutton *)sender { [[wxvoicesdk sharedwxvoice] cancel]; [_button settitle:@"录音" forstate:uicontrolstatenormal]; } @end

以上就是本文对ios开发第三方语言-微信语言的全部介绍,希望对大家有所帮助。

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。