Class File

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

public class File extends ProducerModule
File producer module that reads audio data from a raw file and dispatches it as buffers. It supports real-time streaming and acceleration rate adjustments. This producer module supports both synchronous and asynchronous pipeline operations including pausing and resuming.
  • Constructor Details

    • File

      public File(String path, int sampleRate, int channelCount, int bufferSize)
      Constructs a File producer module with the specified parameters.
      Parameters:
      path - The path to the raw audio file to be read.
      sampleRate - The sample rate of the audio in Hz (e.g., 16000).
      channelCount - The number of audio channels (e.g., 1 for mono, 2 for stereo).
      bufferSize - The size of the audio buffer to be processed in bytes.
  • Method Details

    • setRealTimeStreamingEnabled

      public void setRealTimeStreamingEnabled(boolean enabled)
      Enables or disables real-time streaming. When enabled, the module will attempt to stream audio data in real-time. When disabled, it will read the entire file and dispatch buffers as quickly as possible.
      Parameters:
      enabled - True to enable real-time streaming, false to disable it.
    • setAccelerationRate

      public void setAccelerationRate(double rate) throws Exception
      Sets the acceleration rate for the audio processing. The acceleration rate must be greater than or equal to 1.0. A rate of 1.0 means normal speed, while higher values speed up the processing. Ignored if real-time streaming is disabled.
      Parameters:
      rate - The acceleration rate to set.
      Throws:
      Exception - If the acceleration rate is less than 1.0.
    • runImpl

      protected void runImpl() throws Exception
      Description copied from class: ProducerModule
      Runs the producer module in a blocking manner. The producer state must be OPENED. When calling run pipeline, this method will be called after the open method. The state remains RUNNING until the end and then becomes OPENED.
      Overrides:
      runImpl in class ProducerModule
      Throws:
      Exception - If the producer is not opened or an error occurs during running.
    • openImpl

      protected void openImpl() throws Exception
      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
      Throws:
      Exception - If the producer is already opened or an error occurs during opening.
    • 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.
    • closeImpl

      protected void closeImpl() throws Exception
      Description copied from class: ProducerModule
      Closes the producer module. The producer state must be OPENED or IDLE. When calling stop pipeline, this method will be called after the closeImpl method. When calling run pipeline, this method will be called after the runImpl method. If the closeImpl is asynchronous, the closeImpl should wait until the producer is OPENED.
      Overrides:
      closeImpl in class ProducerModule
      Throws:
      Exception - If an error occurs during closing.
    • pauseImpl

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

      protected void resumeImpl() throws Exception
      Description copied from class: ProducerModule
      Resumes the producer module. The producer state must be PAUSED. When the producer is resumed, the child class needs to update the state to STARTED. When calling resume pipeline, this method will be called. It should initiate the resuming 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:
      resumeImpl in class ProducerModule
      Throws:
      Exception - If an error occurs during resuming.