Class MotorAudioFileConverter

java.lang.Object
com.chatmotorapi.api.transcription.MotorAudioFileConverter

public class MotorAudioFileConverter
extends Object
The MotorAudioFileConverter class is responsible for converting audio files from one format to another.
This class ensures the input and output files are valid before performing the conversion. It supports all audio conversion formats available in FFmpeg.

Example Usage:

 // We assume that the env var MOTOR_API_KEY is set
 // Create a ChatMotor instance.
 ChatMotor chatMotor = ChatMotor.builder().build();
 
 String audioFilePath = "/path/to/audio/file.wav";
 
 // Build the audio file converter request.
 MotorAudioFileConverter motorAudioFileConverter = MotorAudioFileConverter.builder()
     .chatMotor(chatMotor)
     .inputFilePath(audioFilePath)
     .conversionFormat("MP4")
     .build();
 
 // Execute the conversion request.
 MotorLargeResponse motorLargeResponse = motorAudioFileConverter.convert();
 
 if (motorLargeResponse.isResponseOk()) {
     String convertedFilePath = audioFilePath + ".mp4";
     try (InputStream in = motorLargeResponse.getInputStream()) {
         Files.copy(in, Paths.get(convertedFilePath), StandardCopyOption.REPLACE_EXISTING);
     }
 } else {
     System.out.println("throwable   : " + motorLargeResponse.getThrowable());
 }
 

Note: Android platforms are not supported.
  • Method Details

    • builder

      public static MotorAudioFileConverter.Builder builder()
      Static method to initiate building a MotorAudioFileConverter instance.
      Returns:
      a new Builder instance
    • chatMotor

      public ChatMotor chatMotor()
      Gets the ChatMotor to be used in the request.
      Returns:
      the
    • inputFilePath

      public String inputFilePath()
      Returns the orignal audio file path.
      Returns:
      the
    • conversionFormat

      public String conversionFormat()
      Returns the target conversion format.
      Returns:
      the target conversion format
    • execute

      public MotorLargeResponse execute()
      Converts the input audio file to the specified format.
      Returns:
      MotorLargeResponse encapsulating the result of the conversion attempt