MultiMedia_AudioCapturer

    Since:

    1.0

    Version:

    1.0

    Summary

    Files

    Data Structures

    Data Structure Name

    Description

    Defines information about audio capture parameters, including the input source, audio codec format,sampling rate (Hz), number of audio channels, bit rate, and bit width.

    OHOS::Audio::Timestamp

    Represents timestamp information, including the frame position information and high-resolution time source.

    Provides functions for applications to implement audio capturing.

    Enumerations

    Enumeration Name

    Description

    : int32_t { OHOS::Audio::Timestamp::Timebase::MONOTONIC = 0, = 1 }

    Enumerates the time base of this Timestamp. Different timing methods are supported.

    OHOS::Audio::State : uint32_t { , OHOS::Audio::RECORDING, , OHOS::Audio::RELEASED }

    Enumerates the recording states of the current device.

    Functions

    Details

    Enumeration Type Documentation

    State

    Description:

    Enumerates the recording states of the current device.

    Enumerator

    Description

    PREPPARED 

    Prepared

    RECORDING 

    Recording

    STOPPED 

    Stopped

    RELEASED 

    Released

      Description:

      Enumerates the time base of this . Different timing methods are supported.

      Enumerator

      Description

      MONOTONIC 

      Monotonically increasing time, excluding the system sleep time

      BOOTTIME 

      Monotonically increasing time, including the system sleep time

      Function Documentation

      GetAudioTime()

      1. bool OHOS::Audio::AudioCapturer::GetAudioTime ([Timestamp]($api-api-SmartVision-Devices-OHOS-Audio-Timestamp.md) & timestamp, [Timestamp::Timebase]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#gacdafb362a7da91799fa96163bca2a619) base )

      Description:

      Obtains the timestamp.

      Parameters:

      Returns:

      Returns true if the timestamp is successfully obtained; returns false otherwise.

      GetCapturerInfo()

      1. int32_t OHOS::Audio::AudioCapturer::GetCapturerInfo ([AudioCapturerInfo]($api-api-SmartVision-Devices-OHOS-Audio-AudioCapturerInfo.md) & info)

      Description:

      Obtains audio capture parameters.

      This function can be called after SetCapturerInfo is successful.

      Parameters:

      Name

      Description

      info Indicates information about audio capture parameters. For details, see AudioCapturerInfo.

      Returns:

      Returns SUCCESS if the parameter information is successfully obtained; returns an error code defined in otherwise.

      GetFrameCount()

      1. uint64_t OHOS::Audio::AudioCapturer::GetFrameCount ()

      Description:

      Obtains the number of frames required in the current condition, in bytes per sample.

      Returns:

      Returns the number of frames (in bytes per sample) if the operation is successful; returns -1 if an exception occurs.

      GetMinFrameCount()

      1. static bool OHOS::Audio::AudioCapturer::GetMinFrameCount (int32_t sampleRate, int32_t channelCount, [AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) audioFormat, size_t & frameCount )

      Description:

      Obtains the minimum number of frames required in a specified condition, in bytes per sample.

      Parameters:

      Description

      sampleRate Indicates the audio sampling rate, in Hz.
      channelCount Indicates the number of audio recording channels.
      audioFormat Indicates the audio data format.
      frameCount Indicates the minimum number of frames, in bytes per sample.

      Returns:

      Returns true if the minimum number of frames is successfully obtained; returns false otherwise.

      GetStatus()

      Description:

      Obtains the audio capture state.

      Returns:

      Returns the audio capture state defined in .

      Read()

      Description:

      Reads audio data.

      Parameters:

      Returns:

      Returns the size of the audio data read from the device. The value ranges from 0 to userSize. If the reading fails, one of the following error codes is returned: ERR_INVALID_PARAM: The input parameter is incorrect. ERR_ILLEGAL_STATE: The instance is not initialized. ERR_SOURCE_NOT_SET: The state of hardware device instance is abnormal.

      Release()

      1. bool OHOS::Audio::AudioCapturer::Release ()

      Description:

      Releases a local AudioCapturer object.

      Returns:

      Returns true if the object is successfully released; returns false otherwise.

      1. int32_t OHOS::Audio::AudioCapturer::SetCapturerInfo (const [AudioCapturerInfo]($api-api-SmartVision-Devices-OHOS-Audio-AudioCapturerInfo.md) info)

      Description:

      Sets audio capture parameters.

      Parameters:

      Name

      Description

      info Indicates information about audio capture parameters to set. For details, see AudioCapturerInfo.

      Returns:

      Returns SUCCESS if the setting is successful; returns an error code defined in otherwise.

      Start()

      1. bool OHOS::Audio::AudioCapturer::Start ()

      Description:

      Starts audio recording.

      Returns:

      Returns true if the recording is successfully started; returns false otherwise.

      Stop()

      1. bool OHOS::Audio::AudioCapturer::Stop ()

      Description:

      Stops audio recording.

      Returns:

      Returns true if the recording is successfully stopped; returns false otherwise.

      Variable Documentation

      audioFormat

      Description:

      Audio codec format

      bitRate

      Description:

      Bit rate

      bitWidth

      1. [AudioBitWidth](MultiMedia_MediaCommon.md#gae3e35ee2a2222a667fdebbc5b793ca7c) OHOS::Audio::AudioCapturerInfo::bitWidth = [BIT_WIDTH_16](MultiMedia_MediaCommon.md#ggae3e35ee2a2222a667fdebbc5b793ca7ca036f0b45813f96cb6b0f90de1722a780)

      Description:

      Bit width

      channelCount

      1. int32_t OHOS::Audio::AudioCapturerInfo::channelCount = 0

      Description:

      Number of audio channels

      inputSource

      1. [AudioSourceType](MultiMedia_MediaCommon.md#gadc3158e093b995ca7b9b6aa32388ccdd) OHOS::Audio::AudioCapturerInfo::inputSource = [AUDIO_MIC](MultiMedia_MediaCommon.md#ggadc3158e093b995ca7b9b6aa32388ccdda732604b3a24d137429e2b83b31849bce)

      Description:

      Audio source type

      1. int32_t OHOS::Audio::AudioCapturerInfo::sampleRate = 0

      Description:

      Sampling rate

      streamType

      Description:

      Audio stream type