语音识别终极篇

  1. 在工程中 option+command+n 创建一个文件夹命名为 SDK
  2. 把SDK文件拖拽到 工程的SDK文件夹内 (124) (编译后会有18个报错)
  3. 关闭arc : 点击工程的第一个蓝文件(你的工程名) 然后依次点击 Build Phases -> Compile Soures -> JSONKit.m 添加 -fno-objc-arc (这个时候编译 , 没有报错)
  4. 打开网络请求
  5. 倒入类库 类库如下
    libBDVoiceRecognitionClient.a (这个会自己就有)
    libc++.tbd
    libz.1.2.5.tbd
    AudioToolbox.framework
    AVFoundation.framework
    CFNetwork.framework
    CoreLocation.framework
    CoreTelephony.framework
    SystemConfiguration.framework
    GLKit.framework
  6. ViewController.m里面
#import "ViewController.h"
//倒入头文件
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "BDVRRawDataRecognizer.h"
#import "BDVRFileRecognizer.h"


@interface ViewController ()<BDRecognizerViewDelegate>
{
    BDRecognizerViewController *bdvc;
    NSMutableData *Mdata;

    BDRecognizerViewParamsObject *bdvp;
    UITextView *textV;

}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//写一个Button 
//1,设置背景颜色   点击开始说话   以及添加一个点击方法  代码如下:
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(100, 100, 100, 30);
    button.backgroundColor = [UIColor lightGrayColor];
    button.layer.cornerRadius = 10;
    [button setTitle:@"点击说话" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    BDTheme *me = [BDTheme lightBlueTheme];
    //初始化
    bdvc = [[BDRecognizerViewController alloc] initWithOrigin:CGPointMake(20, 100) withTheme:me];

    //设置代理
    bdvc.delegate = self;
    //全屏
    bdvc.enableFullScreenMode = YES;

    bdvp = [[BDRecognizerViewParamsObject alloc] init];

    bdvp.apiKey = @"S0UrbTi31Yi6hTGjssCk0hzR";
    bdvp.secretKey = @"adb44d9f61aa57d86bcf970572c2f568";
    //初始化文本框
    textV = [[UITextView alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];
    textV.layer.borderWidth = 1;
    [self.view addSubview:textV];

}
//按钮的点击方法
- (void)clickButton
{
    Mdata = [[NSMutableData alloc] init];

    [bdvc startWithParams:bdvp];
}
#pragma mark -- 代理方法
/**
 * @brief 语音识别结果返回,搜索和输入模式结果返回的结构不相同
 *
 * @param aBDRecognizerView 弹窗UI
 * @param aResults 返回结果,搜索结果为数组,输入结果也为数组,但元素为字典
 */
- (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults
{
    textV.text = [[[[aResults objectAtIndex:0]objectAtIndex:0]allKeys]objectAtIndex:0];

}
/**
 * @brief 录音数据返回
 *
 * @param recordData 录音数据
 * @param sampleRate 采样率
 */
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate
{
    //拼接
    [Mdata appendData:recordData];
}



@end
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值