带你玩转OpenHarmony AI:打造智能语音子系统

694 篇文章 17 订阅
504 篇文章 1 订阅

简介

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项目功能应该有了初步的了解。

为了帮助到大家能够更有效的学习OpenHarmony 开发的内容,下面特别准备了一些相关的参考学习资料:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

  • 搭建开发环境
  • Windows 开发环境的搭建
  • Ubuntu 开发环境搭建
  • Linux 与 Windows 之间的文件共享
  • ……

系统架构分析:https://qr18.cn/CgxrRy

  • 构建子系统
  • 启动流程
  • 子系统
  • 分布式任务调度子系统
  • 分布式通信子系统
  • 驱动子系统
  • ……

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值