package com.atmob.voiceai.utils;

import android.media.MediaRecorder;
import android.util.Log;

import java.io.IOException;

public class AudioRecorder {

    private static final String TAG = "AudioRecorder";

    private MediaRecorder mediaRecorder;
    private String filePath;

    public AudioRecorder() {
        mediaRecorder = new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    }

    public void setupMediaRecorder(String outputPath) {
        filePath = outputPath;
        mediaRecorder.setOutputFile(filePath);
    }


    public void startRecording() throws IOException {
        Log.d(TAG, "startRecording: " + filePath);
        mediaRecorder.prepare();
        mediaRecorder.start();
    }

    public void setMaxDuration(int maxDuration) {
        mediaRecorder.setMaxDuration(maxDuration);
    }

    public void stopRecording() {
        Log.d(TAG, "stopRecording: " + filePath);
        mediaRecorder.stop();
        mediaRecorder.release();
    }


}
