微信只能开发平台http://pr.weixin.qq.com/,里面包含了微信语音和图像,集成很简单,下载方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开发第三方语言-微信语言的全部介绍,希望对大家有所帮助。
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索ios开发 微信语音聊天、ios 语音识别第三方库、ios开发 第三方播放器、ios开发第三方登录、ios 第三方 sdk开发,以便于您获取更多的相关知识。
时间: 2024-09-18 22:07:37