你好,歡迎來到IOS教程網

 Ios教程網 >> IOS教程 >> 關於IOS教程 >> IOS開發第三方語音-微信語音

IOS開發第三方語音-微信語音

編輯:關於IOS教程

微信只能開發平台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開發第三方語言-微信語言的全部介紹,希望對大家有所幫助。

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved