当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS开发第三方语音-微信语音

IOS开发第三方语音-微信语音

2019年07月24日  | 移动技术网IT编程  | 我要评论

风花仙子外传第2部,数码宝贝十三骑士,ppt背景图片素材

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

先用个有ui界面的sdk

1.装上sdk,引入相关包

2.设置 build settings

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

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

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

3.添加代码

#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 微信智能”或“语音技术由 微信智能提供”的字样。参考如下弹窗:

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

//
// 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开发第三方语言-微信语言的全部介绍,希望对大家有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网