Obtaining and Playing Audios

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

Obtaining Audios

  1. Initialize the public media module by calling hi_mpi_sys_init.
  2. Invoke the hi_mpi_ai_set_pub_attr interface to configure attributes.
  3. Enable the AI device by calling the hi_mpi_ai_enable interface and enable the AI channel by calling the hi_mpi_ai_enable_chn interface.
  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. The process repeats.
  5. When the AI device stops capturing audio, call the hi_mpi_ai_disable_chn interface to disable the channel, and then call the hi_mpi_ai_disable interface to disable the AI device.
  6. Call the hi_mpi_sys_exit interface to release the initialization resources of the common media module.

Playing Audios

  1. Initialize the public media module by calling hi_mpi_sys_init.
  2. Invoke the hi_mpi_ao_set_pub_attr interface to configure attributes.
  3. Enable the AO device by calling the hi_mpi_ao_enable interface, and enable the AO channel by calling the hi_mpi_ao_enable_chn interface.
  4. Periodically obtain data and call the hi_mpi_ao_send_frame API to play audio.
  5. When the audio playback is complete, call hi_mpi_ao_get_chn_delay to obtain the current audio delay of the AO channel. When the delay is 0, call hi_mpi_ao_disable_chn to disable the channel, and then call hi_mpi_ao_disable to disable the AO device.
  6. Call the hi_mpi_sys_exit interface to release the initialization resources of the common media module.