Voice Service

[English]

The voice service provides two-way voice call functionality and supports common features such as AEC (Acoustic Echo Cancellation) and codec.

API Reference

Header File

Functions

voice_handle_t bk_voice_init(voice_cfg_t *cfg)

Create a voice call handle.

Parameters

cfg[in] The voice call configuration.

Returns

The voice handle.

  • Not NULL: Success.

  • NULL: Failed.

bk_err_t bk_voice_deinit(voice_handle_t voice_handle)

Destroy a voice call handle.

Parameters

voice_handle[in] The voice call handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_start(voice_handle_t voice_handle)

Start a voice call.

Parameters

voice_handle[in] The voice call handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_stop(voice_handle_t voice_handle)

Stop a voice call.

Parameters

voice_handle[in] The voice call handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

int bk_voice_read_mic_data(voice_handle_t voice_handle, char *buffer, uint32_t size)

Read microphone data.

Parameters
  • voice_handle[in] The voice call handle.

  • buffer[out] The buffer to store microphone data.

  • size[in] The size of the buffer.

Returns

The actual number of bytes read.

  • Greater than 0: The number of bytes successfully read.

  • Less than or equal to 0: Failed.

int bk_voice_write_spk_data(voice_handle_t voice_handle, char *buffer, uint32_t size)

Write data to the speaker.

Parameters
  • voice_handle[in] The voice call handle.

  • buffer[in] The buffer containing the data to be written.

  • size[in] The size of the data to be written.

Returns

The actual number of bytes written.

  • Greater than 0: The number of bytes successfully written.

  • Less than or equal to 0: Failed.

bk_err_t bk_voice_event_handle(voice_event_handle event_handle, vioce_evt_t event, void *param, void *args)

Handle voice events.

Parameters
  • event_handle[in] The voice event handling function.

  • event[in] The voice event type.

  • param[in] The event parameter.

  • args[in] Additional parameters.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_get_status(voice_handle_t voice_handle, voice_sta_t *status)

Get the status of a voice call.

Parameters
  • voice_handle[in] The voice call handle.

  • status[out] The pointer to store the voice status.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

int bk_voice_get_mic_str(voice_handle_t voice_handle, voice_cfg_t *cfg)
audio_element_handle_t bk_voice_get_spk_element(voice_handle_t voice_handle)

Get the speaker element handle of the voice call.

Parameters

voice_handle[in] The voice call handle.

Returns

The speaker element handle.

  • Not NULL: Success.

  • NULL: Failed.

void bk_voice_cal_vad_buf_size(voice_cfg_t *cfg, voice_handle_t voice_handle)
bk_err_t bk_voice_get_micstr(voice_handle_t voice_handle, audio_element_handle_t *mic_str)

Get the microphone stream handle.

Parameters
  • voice_handle[in] The voice call handle.

  • mic_str[out] The pointer to store the microphone stream handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_get_micstr_type(voice_handle_t voice_handle, mic_type_t *mic_type)

Get the microphone type.

Parameters
  • voice_handle[in] The voice call handle.

  • mic_type[out] The pointer to store the microphone type.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_get_spkstr(voice_handle_t voice_handle, audio_element_handle_t *spk_str)

Get the speaker stream handle.

Parameters
  • voice_handle[in] The voice call handle.

  • spk_str[out] The pointer to store the speaker stream handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_get_spkstr_type(voice_handle_t voice_handle, spk_type_t *spk_type)

Get the speaker type.

Parameters
  • voice_handle[in] The voice call handle.

  • spk_type[out] The pointer to store the speaker type.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_get_aec_alg(voice_handle_t voice_handle, audio_element_handle_t *aec_alg)

Get the AEC algorithm element handle.

Parameters
  • voice_handle[in] The voice call handle.

  • aec_alg[out] The pointer to store the AEC algorithm element handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

Header File

Functions

voice_read_handle_t bk_voice_read_init(voice_read_cfg_t *cfg)

Create a voice read handle to read mic data from voice service.

Parameters

cfg[in] The voice read configuration.

Returns

The voice read handle.

  • Not NULL: Success.

  • NULL: Failed.

bk_err_t bk_voice_read_deinit(voice_read_handle_t voice_read_handle)

Destroy a voice read handle.

Parameters

voice_read_handle[in] The voice read handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_read_start(voice_read_handle_t voice_read_handle)

Start a voice read.

Parameters

voice_read_handle[in] The voice read handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_read_stop(voice_read_handle_t voice_read_handle)

Stop a voice read.

Parameters

voice_read_handle[in] The voice read handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

Header File

Functions

voice_write_handle_t bk_voice_write_init(voice_write_cfg_t *cfg)

Create a voice write handle to write speech data to voice service.

Parameters

cfg[in] The voice write configuration.

Returns

The voice write handle.

  • Not NULL: Success.

  • NULL: Failed.

bk_err_t bk_voice_write_deinit(voice_write_handle_t voice_write_handle)

Destroy a voice write handle.

Parameters

voice_write_handle[in] The voice write handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_write_start(voice_write_handle_t voice_write_handle)

Start a voice write.

Parameters

voice_write_handle[in] The voice write handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_write_stop(voice_write_handle_t voice_write_handle)

Stop a voice write.

Parameters

voice_write_handle[in] The voice write handle.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

bk_err_t bk_voice_write_frame_data(voice_write_handle_t voice_write_handle, char *buffer, uint32_t len)

Write speech data to voice service.

Parameters
  • voice_write_handle[in] The voice write handle.

  • buffer[in] The speech data buffer.

  • len[in] The speech data length.

Returns

Error code.

  • 0: Success.

  • Non-zero: Failed.

API Typedefs

Header File

Structures

struct audio_codec_common_t
struct voice_cfg_t

Public Members

uint32_t read_pool_size

the size(byte) of pool save mic data that has been encode

uint32_t write_pool_size

the size(byte) of pool save speaker data that has not been decode

voice_event_handle event_handle

voice event handle callback

void *args

the parameter of event_handle func

Macros

VOICE_BY_ONBOARD_MIC_SPK_CFG_DEFAULT()
DEFAULT_VOICE_BY_ONBOARD_MIC_SPK_CONFIG()
VOICE_BY_UAC_MIC_SPK_CFG_DEFAULT()
DEFAULT_VOICE_BY_UAC_MIC_SPK_CONFIG()
VOICE_BY_ONBOARD_DUAL_DMIC_MIC_SPK_CFG_DEFAULT()
DEFAULT_VOICE_BY_ONBOARD_DUAL_DMIC_MIC_SPK_CONFIG()

Type Definitions

typedef bk_err_t (*voice_event_handle)(vioce_evt_t, void*, void*)
typedef struct voice *voice_handle_t

Enumerations

enum voice_sta_t

voice status

Values:

enumerator VOICE_STA_NONE
enumerator VOICE_STA_IDLE
enumerator VOICE_STA_RUNNING
enumerator VOICE_STA_STOPPING
enumerator VOICE_STA_STOPED
enum vioce_evt_t

voice event

Values:

enumerator VOC_EVT_NONE
enumerator VOC_EVT_MIC_NOT_SUPPORT
enumerator VOC_EVT_SPK_NOT_SUPPORT
enumerator VOC_EVT_ERROR_UNKNOW
enumerator VOC_EVT_STOP

Header File

Structures

struct voice_read_cfg_t

Public Members

voice_handle_t voice_handle

voice handle

uint32_t max_read_size

the max size of data read from voice handle, used in voice_read_callback

int (*voice_read_callback)(unsigned char *data, unsigned int len, void *args)

call this callback when avlid data has been read

void *args

the pravate parameter of callback

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

audio_mem_type_t mem_type

memory type used, sram or psram

Macros

VOICE_READ_TASK_PRIO
VOICE_READ_CFG_DEFAULT()

Type Definitions

typedef struct voice_read *voice_read_handle_t

Header File

Structures

struct voice_write_cfg_t

Public Members

voice_handle_t voice_handle

voice handle

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

audio_mem_type_t mem_type

memory type used, sram, psram or audio heap

audio_buf_type_t write_buf_type

write buffer type used, frame buffer or ring buffer

int node_size

frame buffer node size or ring buffer pool size

int node_num

frame buffer node number or 1 for ring buffer

Macros

VOICE_WRITE_TASK_PRIO
VOICE_WRITE_POOL_SIZE
VOICE_WRITE_START_THRESHOLD
VOICE_WRITE_PAUSE_THRESHOLD
VOICE_WRITE_CFG_DEFAULT()

Type Definitions

typedef struct voice_write *voice_write_handle_t