微信语音开放平台致力于为开发者提供免费的语音技术,目前已经开放的语音技术包括在线语音识别、在线语音合成等,下面通过本篇文章给大家介绍IOS开发第三方语言-微信语言,需要的朋友可以一起来学习下
微信只能开发平台http://pr.weixin.qq.com/,里面包含了微信语音和图像,集成很简单,下载方demo后会有个文档,按照流程来(因为它只提供了真机的.a文件,所以只能用真机哦,不然会报错)
先用个有UI界面的sdk
1.装上sdk,引入相关包
#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数据恢复软件:PhoneRescue for Mac 2023-09-14
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- Android实现轮询的三种方式 2023-02-17
- Android studio实现动态背景页面 2023-05-23
- Android实现监听音量的变化 2023-03-30
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- Flutter实现底部和顶部导航栏 2022-08-31
- 详解flutter engine 那些没被释放的东西 2022-12-04
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- iOS 对当前webView进行截屏的方法 2023-03-01