TTS Application Note

V1.2

2024/03/06

Revision History

Version

Date

Description

V1.0.0.0

2021/10/21

Stable release

V1.1

2023/06/25

Modify TTS structure

V1.2

2024/03/06

Optimize document content

Table List

Figure List

Glossary

Terms

Definitions

TTS

Text to Speech

1 Introduction

TTS technology is the abbreviation of Text To Speech, It can transforms equipment generated or externally written text information into audio format that be fluent audible language. TTS can be connected by SPP or LE link.

Figure 1-1 TTS Control Flow

2 Configuration

2.1 How to Set up TTS Environment

In app_flags.h set F_APP_TTS_SUPPORT to 1 to support TTS:

#define F_APP_TTS_SUPPORT            1

In mcu cfg tool:

  1. Enable TTS through BLE

    Figure 2-1 Configure TTS Through LE
  2. Enable TTS through SPP

    Figure 2-2 Configure TTS Through SPP
  3. Configure audio route

    Figure 2-3 Configure TTS Audio Information

3 Initialization process

Register tts callback app_tts_bt_cback():

int main(void)
{
    ......
    if (app_cfg_const.tts_support)
    {
        app_tts_init();
    }
    ......
}
void app_tts_init(void)
{
    app_ble_common_adv_cb_reg(app_tts_common_adv_cb);
    bt_mgr_cback_register(app_tts_bt_cback);
}

Init tts advertisement:

void app_ble_common_adv_init(void)
{

4 APP Callback

4.1 Indicates TTS Status to APP

app_tts_bt_cback() function indicates tts status to app:

  1. when event BT_EVENT_HFP_CONN_CMPL or BT_EVENT_A2DP_CONN_CMPL was received
    use app_trigger_ble_adv() to start tts advertisement.

  2. when event BT_EVENT_HFP_DISCONN_CMPL or BT_EVENT_A2DP_DISCONN_CMPL was received
    use app_trigger_stop_ble_link_and_adv() to stop tts advertisement.

  3. when bt_hfp_call_status is BT_HFP_INCOMING_CALL_ONGOING, it means tts start.

  4. when bt_hfp_call_status is BT_HFP_CALL_ACTIVE, it means tts end.

static void app_tts_bt_cback(T_BT_EVENT event_type, void *event_buf, uint16_t buf_len)
{
   ......
    switch (event_type)
    {
    case BT_EVENT_HFP_CONN_CMPL:
        if (app_cfg_const.tts_support)
        {
            T_APP_BR_LINK *p_link;
            p_link = app_link_find_br_link(param->hfp_conn_cmpl.bd_addr);
            if (p_link != NULL)
            {
                if ((SPP_PROFILE_MASK & p_link->connected_profile) == 0)
                {
                    app_tts_start_ble_adv(p_link->bd_addr);
                }
            }
        }
        break;

    case BT_EVENT_A2DP_CONN_CMPL:
        if (app_cfg_const.tts_support)
        {
            T_APP_BR_LINK *p_link;
            p_link = app_link_find_br_link(param->a2dp_conn_cmpl.bd_addr);
            if (p_link != NULL)
            {
                if ((SPP_PROFILE_MASK & p_link->connected_profile) == 0)
                {
                    app_tts_start_ble_adv(p_link->bd_addr);
                }
            }
        }
        break;

    case BT_EVENT_SPP_CONN_CMPL:
        if (app_cfg_const.tts_support)
        {
            T_APP_BR_LINK *p_link;
            p_link = app_link_find_br_link(param->spp_conn_cmpl.bd_addr);
            if (p_link != NULL)
            {
                if (app_db.device_state != APP_DEVICE_STATE_OFF &&
                    app_cfg_nv.bud_role != REMOTE_SESSION_ROLE_SECONDARY)
                {
                    if (app_cfg_const.rtk_app_adv_support && (app_cfg_const.timer_ota_adv_timeout != 0)
                        && !app_cfg_const.enable_power_on_adv_with_timeout)
                    {
                        if (app_ble_common_adv_get_state() != BLE_EXT_ADV_MGR_ADV_DISABLED)
                        {
                            APP_PRINT_TRACE0("app_tts_bt_cback: spp connect, stop common adv");
                            app_ble_common_adv_stop(APP_STOP_ADV_CAUSE_COMMON_FOR_SPP_CONN);
                        }
                    }
                }
            }
        }
        break;

    case BT_EVENT_HFP_DISCONN_CMPL:
        if (app_cfg_const.tts_support)
        {
            T_APP_BR_LINK *p_link;
            p_link = app_link_find_br_link(param->hfp_disconn_cmpl.bd_addr);
            if (p_link != NULL)
            {
                if (app_cfg_nv.bud_role != REMOTE_SESSION_ROLE_SECONDARY)
                {
                    uint8_t remain_profile = (app_db.br_link[p_link->id].connected_profile &
                                              (~(HFP_PROFILE_MASK | HSP_PROFILE_MASK)));
                    if (!(remain_profile & A2DP_PROFILE_MASK))
                    {
                        app_tts_stop_ble_link_and_adv(p_link->bd_addr);
                    }
                }
            }
        }
        break;

    case BT_EVENT_A2DP_DISCONN_CMPL:
        if (app_cfg_const.tts_support)
        {
            T_APP_BR_LINK *p_link;
            p_link = app_link_find_br_link(param->a2dp_disconn_cmpl.bd_addr);
            if (p_link != NULL)
            {
                if (app_cfg_nv.bud_role != REMOTE_SESSION_ROLE_SECONDARY)
                {
                    uint8_t remain_profile = (app_db.br_link[p_link->id].connected_profile & (~A2DP_PROFILE_MASK));
                    if (!(remain_profile & (HFP_PROFILE_MASK | HSP_PROFILE_MASK)))
                    {
                        app_tts_stop_ble_link_and_adv(p_link->bd_addr);
                    }
                }
            }
        }
        break;

    case BT_EVENT_HFP_CALL_STATUS:
        if (app_cfg_const.tts_support)
        {
            T_APP_LE_LINK *p_le_link;
            p_le_link = app_link_find_le_link_by_addr(param->hfp_call_status.bd_addr);

            if ((p_le_link != NULL) && (p_le_link->state == LE_LINK_STATE_CONNECTED))
            {
                //BT_HFP_CALL_INCOMING:tts start, BT_HFP_CALL_ACTIVE:tts end, BT_HFP_CALL_IDLE: call end.
                if (param->hfp_call_status.curr_status == BT_HFP_CALL_INCOMING)
                {
                    ble_set_prefer_conn_param(p_le_link->conn_id,
                                              RWS_LE_DEFAULT_MIN_CONN_INTERVAL,
                                              RWS_LE_DEFAULT_MAX_CONN_INTERVAL,
                                              RWS_LE_DEFAULT_SLAVE_LATENCY,
                                              RWS_LE_DEFAULT_SUPERVISION_TIMEOUT);
                }
            }
        }
        break;
    ......
    }
    ......
}

4.2 Indicates TTS Advertisement Status to APP

app_ble_common_adv_callback() will indicates tts advertisement status to app.