Class AudioRecorder

java.lang.Object
com.vivoka.vsdk.audio.ProducerModule
com.vivoka.vsdk.audio.producers.AudioRecorder

public class AudioRecorder extends ProducerModule
AudioRecorder is a producer module that captures audio from the device's microphone. It supports various configurations such as sample rate, channel configuration, and buffer size. The recorded audio can be processed in real-time or saved for later use.
  • Constructor Details

    • AudioRecorder

      @RequiresPermission("android.permission.RECORD_AUDIO") public AudioRecorder()
      Constructs an AudioRecorder with default parameters. It uses a sample rate of 16000 Hz, mono channel configuration, and a buffer size of 1024 bytes. The audio source is set to VOICE_COMMUNICATION.
    • AudioRecorder

      @RequiresPermission("android.permission.RECORD_AUDIO") public AudioRecorder(int audioSource)
      Constructs an AudioRecorder with the specified audio source. It uses a sample rate of 16000 Hz, mono channel configuration, and a buffer size of 1024 bytes.
      Parameters:
      audioSource - The audio source to use for recording such as VOICE_COMMUNICATION, MIC, etc. For a list of available audio sources, refer to the Android documentation: https://developer.android.com/reference/android/media/MediaRecorder.AudioSource
    • AudioRecorder

      @RequiresPermission("android.permission.RECORD_AUDIO") public AudioRecorder(int sampleRate, int channelConfig, int bufferSizePerChannel)
      Constructs an AudioRecorder with the specified sample rate, channel configuration, and buffer size. The audio source is set to VOICE_COMMUNICATION.
      Parameters:
      sampleRate - The sample rate of the audio (e.g., 16000 Hz).
      channelConfig - The channel configuration (e.g., AudioFormat.CHANNEL_IN_MONO).
      bufferSizePerChannel - The size of the buffer for each channel in bytes.
    • AudioRecorder

      @RequiresPermission("android.permission.RECORD_AUDIO") public AudioRecorder(int sampleRate, int channelConfig, int bufferSizePerChannel, int audioSource)
      Constructs an AudioRecorder with the specified sample rate, channel configuration, buffer size, and audio source. This allows for more flexibility in configuring the audio recording parameters.
      Parameters:
      sampleRate - The sample rate of the audio (e.g., 16000 Hz).
      channelConfig - The channel configuration (e.g., AudioFormat.CHANNEL_IN_MONO).
      bufferSizePerChannel - The size of the buffer for each channel in bytes.
      audioSource - The audio source to use for recording such as VOICE_COMMUNICATION, MIC, etc. For a list of available audio sources, refer to the Android documentation: https://developer.android.com/reference/android/media/MediaRecorder.AudioSource
  • Method Details

    • isRunning

      public boolean isRunning()
      Checks if the AudioRecorder is currently running. This method returns true if the recorder is actively capturing audio, false otherwise.
      Overrides:
      isRunning in class ProducerModule
      Returns:
      True if the producer module is running, false otherwise.
    • openImpl

      protected void openImpl()
      Description copied from class: ProducerModule
      Opens the producer module. This method prepares the module for processing audio data. This method is called by the pipeline before starting or running the producer.
      Overrides:
      openImpl in class ProducerModule
    • startImpl

      protected void startImpl() throws Exception
      Description copied from class: ProducerModule
      Starts the producer module in a non-blocking manner. The producer state must be OPENED. When calling start pipeline, this method will be called after the open method. startImpl() should initiate the producer and return immediately without waiting for processing to complete and update the state to STARTED when it is done.
      Overrides:
      startImpl in class ProducerModule
      Throws:
      Exception - If an error occurs during starting.
    • stopImpl

      protected void stopImpl() throws Exception
      Description copied from class: ProducerModule
      Stops the producer module. The producer state must be STARTED. When calling stop pipeline, this method will be called. It should initiate the stopping process and return immediately without waiting for it to complete. It should make sure that the state is updated to OPENED when it is done.
      Overrides:
      stopImpl in class ProducerModule
      Throws:
      Exception - If an error occurs during stopping.