服务器之家

服务器之家 > 正文

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

时间:2020-12-23 15:16     来源/作者:幻想无极

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

先用个有ui界面的sdk

1.装上sdk,引入相关包

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

2.设置 build settings

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

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

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开发第三方语音-微信语音

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

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

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址 2020-08-12
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
返回顶部