IOS开发第三方语音的技术详解
来源:爱站网时间:2018-11-14编辑:网友分享
微信的语音平台开发者提供免费的语音技术,现已开通的语音技术包括在线语音识别等等,我们使用是苹果手机也不愿落人之后,今天你们就随着爱站技术小编的步伐一起来了解IOS开发第三方语音的技术详解吧!
微信的语音平台开发者提供免费的语音技术,现已开通的语音技术包括在线语音识别等等,我们使用是苹果手机也不愿落人之后,今天你们就随着爱站技术小编的步伐一起来了解IOS开发第三方语音的技术详解吧!
IOS开发第三方语音的技术详解
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 (){ 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 ()@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开发第三方语音的技术详解的全部介绍,希望对大家有所帮助,也希望大家继续支持爱站技术频道!