uniapp-app对接百度智能云语音识别

一、语音识别服务申请

在manifest.json开启Speech语音输入权限,如下图

Id和密钥需去百度智能云官网进行注册应用,并购买语音识别服务(第一次使用可免费领取限量的资源)

二、使用

1、点击开始录音

// #ifdef APP-PLUS
	plus.speech.startRecognize({
	    engine: 'baidu',
	    lang: 'zh-cn',
	    'userInterface': false,
	    'continue': true
	});
// #endif

2、点击停止录音

// #ifdef APP-PLUS
    plus.speech.stopRecognize();
// #endif

3、监听语音识别

// 在onLoad中编写
// #ifdef APP-PLUS
    plus.speech.addEventListener('start', this.ontStart, false);
    plus.speech.addEventListener('volumeChange', this.onVolumeChange, false);
    plus.speech.addEventListener('recognizing', this.onRecognizing, false);
    plus.speech.addEventListener('recognition', this.onRecognition, false);
    plus.speech.addEventListener('end', this.onEnd, false);
// #endif

4、监听方法

ontStart() {
    this.title = '开始录音';
    this.text = '';
},
onVolumeChange(e) {
	console.log(e.volume);
},
onRecognizing(e) {
	this.partialResult = e.partialResult;			
	console.log(e.partialResult);
},
onRecognition(e) {
	this.text += e.result;
	this.text?(this.text+='\n'):this.text='';
	this.result = this.text;
	this.partialResult = e.result;
	console.log(e.result);
},
onEnd() {
    // 结束录音
	if(!this.text||this.text==''){
	    plus.nativeUI.toast('没有识别到内容');
	}
	this.result = this.text;
	this.title = '未开始';
	this.partialResult = '';
},

以上步骤详见uniapp官方文档

提示:该功能只能使用自定义基座或云端包才能生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值