你好,歡迎來到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開辟第三方說話-微信說話的全體引見,願望對年夜家有所贊助。

【IOS開辟第三方語音-微信語音】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

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