简介

AI时代,智者当先,判断一个终端设备是否智能,语音能力是必不可缺的。智能家居、智慧厨房、智能汽车等等,所有衣食住行都在往智能方向倒退,那咱们该如何在OpenAtom OpenHarmony(简称“OpenHarmony”)零碎现有的能力下,搭建一套残缺的语音子系统呢?

本文介绍了博泰车联网的研发同学如何搭建一套属于OpenHarmony的语音子系统CarVoiceAssistant,并以车载交互的状态研发语音助理我的项目的过程。

成果展现

开发环境

硬件平台:DAYU200
零碎版本:OpenHarmony 3.1 Release
开发语言:C++,JS,eTS
IDE:VS Code、DevEco Studio

性能介绍

交互流程介绍

本样例蕴含两个要害能力库:QGWebRTCVAD,用作无效音频检测和截取;QGPocketSphinx,用作唤醒词训练和辨认,次要流程如下:

设施唤醒之后,须要继续采集用户音频数据,并传输给博泰QingAI云端,做继续辨认和最终语义辨认,辨认之后客户端依据语义做具体动作执行 。

两步带你实现语义助理集成

1.语音子系统集成
(1)下载语音助理我的项目代码
(2)解压【data.zip】文件(../../dev/team_x/PATEO_CarVoiceAssistant/data.zip)
(3)应用hdc工具将data中的文件发送到OpenHarmony零碎中

#1. 将动静库和资源文件发送到OpenHarmony零碎中   # 如果提醒Read only system;进入OH零碎后执行:"mount -o rw,remount /"命令后再发送文件   hdc_std.exe file send voice_assistant_service.xml /system/profile/   hdc_std.exe file send libcarvoiceassistant.z.so /system/lib/module/libcarvoiceassistant.z.so   hdc_std.exe file send libvoiceassistant_service.z.so /system/lib/libvoiceassistant_service.z.so   hdc_std.exe file send libpocketsphinx.z.so /system/lib/module/libpocketsphinx.z.so   hdc_std.exe file send libps_vad.z.so /system/lib/module/libps_vad.z.so   hdc_std.exe file send libvoicecloud.z.so /system/lib/libvoicecloud.z.so   hdc_std.exe file send voice_assistant_service.cfg /system/etc/init/      #在零碎/system/etc/下,创立目录pocketsphinx; 创立目录命令: mkdir /system/etc/pocketsphinx   hdc_std.exe file send voice_tip.mp3 /system/etc/pocketsphinx/   hdc_std.exe file send zh.tar /system/etc/pocketsphinx/      #在OpenHarmony零碎中解压zh.tar   tar xvf zh.tar      #确保/system/etc/pocketsphinx/下文件目录构造如下:   ├── zh   │   ├── zh   │   │   ├── feat.params   │   │   ├── feature_transform   │   │   ├── mdef   │   │   ├── means   │   │   ├── mixture_weights   │   │   ├── noisedict   │   │   ├── transition_matrices   │   │   └── variances   │   ├── zh_cn.dic   │   └── zh_cn.lm.bin   ├── voice_tip.mp3      #重启零碎

2.语音助理App集成
(1)引入语音助理申明文件

import carvoiceassistant from '@ohos.carvoiceassistant'// 获取语音助理治理类let voiceManager = carvoiceassistant.getManager(); 

(2)开启唤醒

voiceManager.enableWakeUp()

(3)注册热词

voiceManager.registerHotwords(JSON.stringify(hotwords))

(4)经纬度设置,用于云语音定位地理位置;例如“今天天气怎么样?”语义能够返回设置的经纬度地区的天气信息

voiceManager.setCoord(23.025978, 113.754969)

(5)监听回调,能够监听辨认状态、语义解析回调、TTS播报状态

voiceManager.on(carvoiceassistant.EventType.VoiceAssistantEventTypeRecognizeStateChanged, (err, data) => {         this.isRecognizing = data['isRecognizing']         if (this.isRecognizing) {           this.voiceText = "我正在听..."         } else if (this.voiceText == "我正在听...") {           this.voiceText = ''         }       })       voiceManager.on(carvoiceassistant.EventType.VoiceAssistantEventTypeAsrResult, (err, data) => {         let json: AsrModel = JSON.parse(data['result'])         ...       })       voiceManager.on(carvoiceassistant.EventType.VoiceAssistantEventTypeTTSPlayStateChanged, (err, data) => {         let isPlaying = data["isPlaying"]         if (isPlaying == false) {           if (this.needDeclare) {             this.isUserStopRecognizing = false;             this.needDeclare = false;             voiceManager.startRecognize();           }           this.voiceText = '';         }       })     }

(6)辨认接口

voiceManager.startRecognize(); //开始辨认voiceManager.stopRecognize(); //进行辨认

以上步骤实现后,你也就实现了OpenHarmony零碎下语义能力集成。

总结

通过本篇文章介绍,您对OpenHarmony零碎下CarVoiceAssistant我的项目性能应该有了初步的理解。如果您对本篇文章内容以及所实现的Demo感兴趣,能够依据本篇文章介绍自行下载CarVoiceAssistant源码进行钻研和应用。同时也欢送更多开发者与咱们共享开发成绩,分享技术解读与教训心得。

OpenHarmony PATEO_CarVoiceAssistant仓库地址https://gitee.com/openharmony...

参考链接

博泰OpenHarmony语音助理https://gitee.com/openharmony...常识体系工作组https://gitee.com/openharmony...