微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > mt2523 如何开启语音识别(Siri)

mt2523 如何开启语音识别(Siri)

时间:10-02 整理:3721RD 点击:
当前FAQ是基于SDK 4.0.0的版本,依赖于Sink module来实现,请确保您的版本高于SDK 4.0.0并且已经包含了sink的module

1. 添加一个新的Sink event来通知语音识别状态的变化
File: middleware\mtk\bt_sink\inc\bt_sink_srv.h
#define BT_SINK_SRV_EVENT_HF_VOICE_RECOGNITION_CHANGE
(BT_SINK_SRV_EVENT_HF_START + 3)

2. 添加对应event的结构体
typedef struct {
bt_bd_addr_t bt_addr;
bool enable;
} bt_sink_srv_voice_recognition_status_t;
typedef union {
bt_sink_srv_state_change_t state_change;
bt_sink_srv_caller_information_t caller_info;
bt_sink_srv_connection_information_t connection_info;
bt_sink_srv_volume_change_t volume_change;
bt_sink_srv_voice_recognition_status_t voice_recognition; // 添加此处
} bt_sink_srv_event_param_t;

3. 增加一个长命令的定义,因为开启Apple客制化AT command的命令长度超过BT_SINK_SRV_HF_CMD_LENGTH (12)
File: middleware\MTK\bt_sink\inc\bt_sink_srv_hf.h
#define BT_SINK_SRV_HF_LONG_CMD_LENGTH 48

4. 添加一个feature configuration的枚举类型(根据Apple的spec来定义)
File: middleware\MTK\bt_sink\inc\bt_sink_srv_hf.h
typedef enum {
BT_SINK_SRV_HF_APL_NONE = 0x0001, /* reserved */
BT_SINK_SRV_HF_APL_BAT_REPORT = 0x0002, /* Battery reporting */
BT_SINK_SRV_HF_APL_DOCKED = 0x0004, /* is docked or powered */
BT_SINK_SRV_HF_APL_SIRI_REPORT = 0x0008, /* Siri status reporting */
BT_SINK_SRV_HF_APL_NR_REPORT = 0x0010 /* noise reduction(NR) status
reporting */
} bt_sink_srv_hf_apl_features_t;

5. 添加激活Apple客制化AT command的API声明
File: middleware\MTK\bt_sink\inc\bt_sink_srv_hf.h
void bt_sink_srv_hf_enable_apl_custom_commands(uint32_t handle,
bt_sink_srv_hf_apl_features_t features);
//...
#define BT_SINK_SRV_HF_ENABLE_CUSTOM_CMDS(handle, command)
bt_hfp_send_command(handle, (uint8_t *)command,
(uint16_t)bt_sink_srv_strlen(command))

6. 添加API定义
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf_call_manager.c
void bt_sink_srv_hf_enable_apl_custom_commands(uint32_t handle,
bt_sink_srv_hf_apl_features_t features)
{
char buffer[BT_SINK_SRV_HF_LONG_CMD_LENGTH];
/* Enable custom AT commands */
/* Format: AT+XAPL=vendorID-productID-version,features */
snprintf((char *)buffer,
BT_SINK_SRV_HF_LONG_CMD_LENGTH,
"AT+XAPL=MTK-HB-0400,%d",
features);
BT_SINK_SRV_HF_ENABLE_CUSTOM_CMDS(handle, buffer);
}

7. 在HFP SLC(service level connection)连接完成之后,调用API激活Apple客制化AT command
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf.c
bt_status_t bt_sink_srv_hf_common_callback(bt_msg_type_t msg, bt_status_t
status, void *buffer)
{
switch (msg) {
//....
case BT_HFP_SLC_CONNECTED_IND: {
//....
// Add start
bt_sink_srv_hf_enable_apl_custom_commands(bt_sink_srv_hf_p->handle,
BT_SINK_SRV_HF_APL_SIRI_REPORT);
// Add End
bt_sink_srv_pbapc_connect(address_p); // Add before this line
bt_sink_srv_cm_profile_status_notify(address_p, BT_SINK_SRV_TYPE_HFP,
true);
//....
}
break;
//...
}
//...
}

8. 接收bluetooth stack的voice recognition的event并通知上层
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf.c
bt_status_t bt_sink_srv_hf_common_callback(bt_msg_type_t msg, bt_status_t
status, void *buffer)
{
switch (msg) {
//...
// Add start
case BT_HFP_VOICE_RECOGNITION_IND: {
bt_hfp_voice_recognition_ind_t *message = (bt_hfp_voice_recognition_ind_t
*)buffer;
bt_sink_srv_event_param_t *event =
bt_sink_srv_memory_alloc(sizeof(*event));
if (NULL != event) {
address_p = bt_hfp_get_bd_addr_by_handle(message->handle);
bt_sink_srv_meMCPy(&event->voice_recognition.bt_addr, address_p,
sizeof(*address_p));
event->voice_recognition.enable = message->enable;
bt_sink_srv_event_callback(BT_SINK_SRV_EVENT_HF_VOICE_RECOGNITION_CHANGE,
event);
bt_sink_srv_memory_free(event);
}
}
break;
// Add End
default:
break;
}

9. include "bt_sink_srv_action.h"的头文件,在需要激活语音识别的地方调用API
以UT/IT为例,输入AT+BTSINKIT=VRA1来激活语音识别(Siri),输入AT+BTSINKIT=VRA0停止语音识别
File: middleware\MTK\bt_sink\src\bt_sink_srv_ATCI_cmd.c
static int16_t bt_sink_srv_cmd_entry(const char *string)
{
if (0 == bt_sink_srv_memcmp(string, CMD_PARAM("DSC"))) { //DISCOVERABLE
bt_sink_srv_action_send(BT_SINK_SRV_ACTION_DISCOVERABLE, NULL);
} else if (0 == bt_sink_srv_memcmp(string, CMD_PARAM("VRA"))) { // VOICE
RECOGNITION ACTIVATE
// Please refer to the following usage to enable Siri
bool active = (bool)((*(string + 3)) - '0');
bt_sink_srv_action_send(BT_SINK_SRV_ACTION_VOICE_RECOGNITION_ACTIVATE,
&active);
}
//...
}

10. 根据需要接收语音识别状态改变的event
File: project\MT2523_HDK\apps\IOT_sdk_demo\src\bt_audio\sink\bt_sink_app_event.c
bt_sink_srv_status_t bt_sink_app_event_handler(bt_sink_srv_event_t
event_id, void *parameters)
{
bt_sink_srv_event_param_t *event = (bt_sink_srv_event_param_t
*)parameters;
bt_sink_app_report("[Sink] event:0x%x", event_id);
switch (event_id) {
//...
// Add start
case BT_SINK_SRV_EVENT_HF_VOICE_RECOGNITION_CHANGE:
bt_sink_app_report("[Sink] Voice recognition
address:0x%2x,0x%2x,0x%2x,0x%2x,0x%2x,0x%2x",
event->voice_recognition.bt_addr[5],
event->voice_recognition.bt_addr[4],
event->voice_recognition.bt_addr[3],
event->voice_recognition.bt_addr[2],
event->voice_recognition.bt_addr[1],
event->voice_recognition.bt_addr[0]);
bt_sink_app_report("[Sink] Voice recognition enable:%d", event-
>voice_recognition.enable);
break;
// Add End
default:
break;
}
更多信息,请参见Apple官方的文档"BluetoothDesignGuidelines.pdf",第六章节("Siri")

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top