Audio Obtaining and Playing

This section describes the API call sequence and precautions for obtaining and playing audios.

Obtaining Audios

  1. Call hi_mpi_sys_init to initialize the common module.
  2. Call hi_mpi_ai_set_pub_attr to configure attributes.
  3. Call hi_mpi_ai_enable to enable an AI device, and call hi_mpi_ai_enable_chn to enable an AI channel.
  4. Call hi_mpi_ai_get_frame to obtain the recording data for processing, and then call hi_mpi_ai_release_frame to release audio frames. Repeat this step.
  5. When audio capturing stops, call hi_mpi_ai_disable_chn to disable the channel, and then call hi_mpi_ai_disable to disable the AI device.
  6. Call hi_mpi_sys_exit to free the initialization resources of the common module.

Playing Audios

  1. Call hi_mpi_sys_init to initialize the common module.
  2. Call hi_mpi_ao_set_pub_attr to configure attributes.
  3. Call hi_mpi_ao_enable to enable an AO device, and call hi_mpi_ao_enable_chn to enable an AO channel.
  4. Periodically obtain data and call hi_mpi_ao_send_frame to play the audio.
  5. When the audio playback ends, obtain the current audio delay in the AO channel by calling hi_mpi_ao_get_chn_delay. When the delay becomes 0, disable the AO channel by calling hi_mpi_ao_disable_chn, and then disable the AO device by calling hi_mpi_ao_disable.
  6. Call hi_mpi_sys_exit to free the initialization resources of the common module.