本文为您介绍如何开通与使用腾讯云物联网开发平台语音识别服务。
限制条件
仅支持在以下地区激活设备开通语音识别服务:
中国大陆(不含港澳台地区)
申请开通语音识别服务
语音识别服务接入指南
步骤一:开通语音识别服务
1. 登录 物联网开发平台控制台 ,地区选择“中国区”并创建项目及产品,详情请参见 产品定义。
2. 选择已创建的项目进入项目详情页,单击左侧导航菜单产品开发进入产品列表页。
3. 选择已创建的产品进入产品详情页,单击数据模板,在右侧增值服务菜单栏中,单击“语音识别”处按钮即可开通成功。
步骤二:创建设备
单击控制台左侧导航菜单产品开发,选择产品进入产品详情页,单击设备调试 > 新建设备,填写相关信息单击保存即可。
注意:
当产品下存在设备时,不可更改增值服务开关状态。
若删除已开通增值服务的设备,所购买 License 数量不可恢复。
设备接入指引
腾讯云物联网开发平台(IoT Explorer)使用语音识别(Automatic Speech Recognition,ASR)产品功能,并结合 C SDK 的 ASR 示例
asr_data_template_sample
快速体验 ASR 功能。配置设备信息
修改设备信息配置
device_info.json
,将创建的 ASR 的产品和设备信息对应填入,获取设备信息可参考 设备调试。
将 ASR 结果返回依赖的数据模板属性修改为系统属性,与用户的数据模板解耦示例代码如下:{"auth_mode":"KEY","productId":"PRODUCT_ID", //ASR产品ID"productSecret":"YOUR_PRODUCT_SECRET","deviceName":"YOUR_DEV_NAME", //ASR设备名"key_deviceinfo":{"deviceSecret":"YOUR_IOT_PSK" //ASR设备密钥},"cert_deviceinfo":{"devCertFile":"YOUR_DEVICE_CERT_FILE_NAME","devPrivateKeyFile":"YOUR_DEVICE_PRIVATE_KEY_FILE_NAME"},"region":"china"}
修改编译选项
修改 CMakeLists.txt(以密钥认证设备为例)使能 ASR 和资源管理功能(ASR 功能依赖资源管理功能)有以下两种方式:
使用 cmake 编译:
set(BUILD_TYPE "release")set(COMPILE_TOOLS "gcc")set(PLATFORM "linux")set(FEATURE_RESOURCE_UPDATE_ENABLED ON)set(FEATURE_ASR_ENABLED ON)set(FEATURE_AUTH_MODE "KEY")
执行脚本编译:
./cmake_build.sh
使用 makefile 编译:
PLATFORM_CC = gccPLATFORM_AR = arPLATFORM_OS = linuxFEATURE_RESOURCE_UPDATE_ENABLED = yFEATURE_ASR_ENABLED = y
执行 make 编译:
make
asr_data_template_sample
示例输出位于output/release/bin
文件夹中。示例说明
使用 ASR 功能,需要进行以下操作:
1.1 调用接口
IOT_Asr_Init
初始化asr_client
。1.2 如果是文件或者一句话识别,则调用
IOT_Asr_RecordFile_Request
,传入请求参数、文件名及回调即可;如果是实时语音,则调用IOT_Asr_Realtime_Request
,传入实时音频数据、请求参数及回调,同时,音频数据的编码需要在发起请求前完成。两个接口的调用成功的情况下返回值是request_id
,对应的结果会在回调中返回,返回结果会带上对应的request_id
,即 ASR 的结果返回只支持异步。asr_data_template_sample
展示了 ASR 在文件、一句话和实时语音三种使用场景下如何使用上述 API,通过修改示例的宏定义DEMO_ASR
选择对应的示例场景,三个场景的数据来源都使用测试文件tools/test_file/test.wav
,编译后,该文件将会被拷贝到output/release/bin/test_file/test.wav
,如果需要使用自己的测试文件,则可以通过替换该测试文件即可。#define DEMO_ASR_FILE 0#define DEMO_ASR_REALTIEM 1#define DEMO_ASR_SENTENCE 2#define DEMO_ASR DEMO_ASR_SENTENCE
使用场景说明
运行说明
将
DEMO_ASR
配置为DEMO_ASR_FILE
,对应示例 ASR 文件识别的使用场景:./asr_data_template_sampleINF|2020-11-10 16:24:19|qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.1.4, Product_ID: W0MHQCSFN5, Device_Name: dev002INF|2020-11-10 16:24:19|mqtt_client.c|IOT_MQTT_Construct(125): mqtt connect with id: q4ZhF successINF|2020-11-10 16:24:19|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=2717INF|2020-11-10 16:24:19|data_template_client.c|IOT_Template_Construct(936): Sync device data successfullyINF|2020-11-10 16:24:19|asr_data_template_sample.c|main(379): Cloud Device Construct SuccessINF|2020-11-10 16:24:19|asr_data_template_sample.c|_register_data_template_property(227): data template property=asr_response registered.INF|2020-11-10 16:24:19|asr_data_template_sample.c|main(394): Register data template propertys SuccessINF|2020-11-10 16:24:20|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=2718INF|2020-11-10 16:24:22|asr_data_template_sample.c|main(492): record file test.wav's request_id 1INF|2020-11-10 16:24:24|asr_data_template_sample.c|main(492): record file test.wav's request_id 2INF|2020-11-10 16:24:26|asr_data_template_sample.c|main(492): record file test.wav's request_id 3INF|2020-11-10 16:24:27|asr_data_template_sample.c|main(492): record file test.wav's request_id 4INF|2020-11-10 16:24:29|asr_data_template_sample.c|main(492): record file test.wav's request_id 5INF|2020-11-10 16:24:31|asr_data_template_sample.c|main(492): record file test.wav's request_id 6INF|2020-11-10 16:24:32|asr_data_template_sample.c|asr_result_cb(340): request_id:3: 1/1 text:[0:0.000,0:2.800] 北京科技馆。INF|2020-11-10 16:24:32|asr_data_template_sample.c|asr_result_cb(340): request_id:2: 1/1 text:[0:1.040,0:3.100] 北京科技馆。INF|2020-11-10 16:24:33|asr_data_template_sample.c|main(492): record file test.wav's request_id 7INF|2020-11-10 16:24:35|asr_data_template_sample.c|main(492): record file test.wav's request_id 8INF|2020-11-10 16:24:36|asr_data_template_sample.c|asr_result_cb(340): request_id:1: 1/1 text:[0:0.000,0:2.800] 北京科技馆。INF|2020-11-10 16:24:36|asr_data_template_sample.c|asr_result_cb(340): request_id:4: 1/1 text:[0:0.000,0:2.800] 北京科技馆。
将
DEMO_ASR
配置为DEMO_ASR_REALTIEM
,对应示例 ASR 一句话识别的使用场景:./asr_data_template_sampleINF|2020-11-10 16:21:00|qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.1.4, Product_ID: W0MHQCSFN5, Device_Name: dev002INF|2020-11-10 16:21:00|mqtt_client.c|IOT_MQTT_Construct(125): mqtt connect with id: oLbdC successINF|2020-11-10 16:21:00|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=53209INF|2020-11-10 16:21:00|data_template_client.c|IOT_Template_Construct(936): Sync device data successfullyINF|2020-11-10 16:21:00|asr_data_template_sample.c|main(379): Cloud Device Construct SuccessINF|2020-11-10 16:21:00|asr_data_template_sample.c|_register_data_template_property(227): data template property=asr_response registered.INF|2020-11-10 16:21:00|asr_data_template_sample.c|main(394): Register data template propertys SuccessINF|2020-11-10 16:21:01|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=53210INF|2020-11-10 16:21:03|asr_data_template_sample.c|main(508): record file test.wav's request_id 1INF|2020-11-10 16:21:04|asr_data_template_sample.c|main(508): record file test.wav's request_id 2INF|2020-11-10 16:21:05|asr_data_template_sample.c|main(508): record file test.wav's request_id 3INF|2020-11-10 16:21:06|asr_data_template_sample.c|main(508): record file test.wav's request_id 4INF|2020-11-10 16:21:06|asr_data_template_sample.c|asr_result_cb(340): request_id:1: 1/1 text:北京科技馆。INF|2020-11-10 16:21:07|asr_data_template_sample.c|main(508): record file test.wav's request_id 5INF|2020-11-10 16:21:07|asr_data_template_sample.c|asr_result_cb(340): request_id:2: 1/1 text:北京科技馆。INF|2020-11-10 16:21:07|asr_data_template_sample.c|asr_result_cb(340): request_id:3: 1/1 text:北京科技馆。INF|2020-11-10 16:21:08|asr_data_template_sample.c|main(508): record file test.wav's request_id 6INF|2020-11-10 16:21:08|asr_data_template_sample.c|asr_result_cb(340): request_id:4: 1/1 text:北京科技馆。
将
DEMO_ASR
配置为DEMO_ASR_SENTENCE
,对应示例 ASR 实时语音识别的使用场景:./asr_data_template_sampleINF|2020-11-10 16:25:39|qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.1.4, Product_ID: W0MHQCSFN5, Device_Name: dev002INF|2020-11-10 16:25:39|mqtt_client.c|IOT_MQTT_Construct(125): mqtt connect with id: 1tBx2 successINF|2020-11-10 16:25:39|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=45977INF|2020-11-10 16:25:39|data_template_client.c|IOT_Template_Construct(936): Sync device data successfullyINF|2020-11-10 16:25:39|asr_data_template_sample.c|main(379): Cloud Device Construct SuccessINF|2020-11-10 16:25:39|asr_data_template_sample.c|_register_data_template_property(227): data template property=asr_response registered.INF|2020-11-10 16:25:39|asr_data_template_sample.c|main(394): Register data template propertys SuccessINF|2020-11-10 16:25:40|asr_data_template_sample.c|event_handler(88): subscribe success, packet-id=45978INF|2020-11-10 16:25:42|asr_data_template_sample.c|main(556): realtime request_id 1INF|2020-11-10 16:25:43|asr_data_template_sample.c|main(556): realtime request_id 2INF|2020-11-10 16:25:44|asr_data_template_sample.c|main(556): realtime request_id 3INF|2020-11-10 16:25:44|asr_data_template_sample.c|asr_result_cb(340): request_id:1: 0/0 text:NULLINF|2020-11-10 16:25:45|asr_data_template_sample.c|main(556): realtime request_id 4INF|2020-11-10 16:25:45|asr_data_template_sample.c|asr_result_cb(340): request_id:2: 1/0 text:NULLINF|2020-11-10 16:25:46|asr_data_template_sample.c|main(556): realtime request_id 5INF|2020-11-10 16:25:46|asr_data_template_sample.c|asr_result_cb(340): request_id:3: 2/0 text:NULLINF|2020-11-10 16:25:46|asr_data_template_sample.c|main(556): realtime request_id 6INF|2020-11-10 16:25:46|asr_data_template_sample.c|asr_result_cb(340): request_id:4: 3/0 text:NULLINF|2020-11-10 16:25:47|asr_data_template_sample.c|main(556): realtime request_id 7INF|2020-11-10 16:25:47|asr_data_template_sample.c|asr_result_cb(340): request_id:5: 4/0 text:NULLINF|2020-11-10 16:25:48|asr_data_template_sample.c|main(556): realtime request_id 8INF|2020-11-10 16:25:48|asr_data_template_sample.c|asr_result_cb(340): request_id:6: 5/0 text:NULLINF|2020-11-10 16:25:49|asr_data_template_sample.c|main(556): realtime request_id 9INF|2020-11-10 16:25:49|asr_data_template_sample.c|asr_result_cb(340): request_id:7: 6/0 text:NULLINF|2020-11-10 16:25:50|asr_data_template_sample.c|main(556): realtime request_id 10INF|2020-11-10 16:25:50|asr_data_template_sample.c|asr_result_cb(340): request_id:8: 7/0 text:NULLINF|2020-11-10 16:25:51|asr_data_template_sample.c|main(556): realtime request_id 11INF|2020-11-10 16:25:51|asr_data_template_sample.c|asr_result_cb(340): request_id:9: 8/0 text:NULLINF|2020-11-10 16:25:52|asr_data_template_sample.c|main(556): realtime request_id 12INF|2020-11-10 16:25:52|asr_data_template_sample.c|asr_result_cb(340): request_id:10: 9/0 text:NULLINF|2020-11-10 16:25:53|asr_data_template_sample.c|main(556): realtime request_id 13INF|2020-11-10 16:25:53|asr_data_template_sample.c|asr_result_cb(340): request_id:11: 10/0 text:NULLINF|2020-11-10 16:25:53|asr_data_template_sample.c|main(556): realtime request_id 14INF|2020-11-10 16:25:53|asr_data_template_sample.c|asr_result_cb(340): request_id:12: 11/0 text:NULLINF|2020-11-10 16:25:54|asr_data_template_sample.c|main(556): realtime request_id 15INF|2020-11-10 16:25:54|asr_data_template_sample.c|asr_result_cb(340): request_id:13: 12/0 text:北京科技。INF|2020-11-10 16:25:55|asr_data_template_sample.c|main(556): realtime request_id 16INF|2020-11-10 16:25:55|asr_data_template_sample.c|asr_result_cb(340): request_id:14: 13/0 text:北京科技。INF|2020-11-10 16:25:56|asr_data_template_sample.c|main(556): realtime request_id 17INF|2020-11-10 16:25:56|asr_data_template_sample.c|asr_result_cb(340): request_id:15: 14/0 text:北京科技馆。INF|2020-11-10 16:25:57|asr_data_template_sample.c|main(556): realtime request_id 18INF|2020-11-10 16:25:57|asr_data_template_sample.c|asr_result_cb(340): request_id:16: 15/0 text:NULLINF|2020-11-10 16:25:58|asr_data_template_sample.c|main(556): realtime request_id 19INF|2020-11-10 16:25:58|asr_data_template_sample.c|asr_result_cb(340): request_id:17: 16/0 text:NULLINF|2020-11-10 16:25:59|asr_data_template_sample.c|main(556): realtime request_id 20INF|2020-11-10 16:25:59|asr_data_template_sample.c|asr_result_cb(340): request_id:18: 17/0 text:NULLINF|2020-11-10 16:26:00|asr_data_template_sample.c|main(556): realtime request_id 21