int mAudioSource = MediaRecorder.AudioSource.MIC;
int mSampleRate = 44100;
int mChannelCount = AudioFormat.CHANNEL_IN_STEREO;
int mAudioFomat = AudioFormat.ENCODING_PCM_16BIT;
int mBufferSize = AudioTrack.getMinBufferSize(mSampleRate, mChannelCount, mAudioFomat);
String mFilepath;
AudioRecord mAudioRecord = null;
public boolean isRecording = false;
Thread mRecordThead = new Thread(new Runnable() {
@Override
public void run() {
byte[] readDate = new byte[mBufferSize];
mFilepath = Environment.getExternalStorageDirectory().getAbsolutePath() +"/record.mp3";
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(mFilepath);
}catch(FileNotFoundException e){e.printStackTrace();}
while (isRecording)
{
int ret = mAudioRecord.read(readDate, 0, mBufferSize);
//Log.d(TAG,)
try
{
fos.write(readDate, 0, mBufferSize);
}catch(Exception e){e.printStackTrace();}
}
mAudioRecord.stop();
mAudioRecord.release();
mAudioRecord = null;
try
{
fos.close();
}catch (IOException e){e.printStackTrace();}
}
});
public void StartRecording()
{
if(isRecording)
return;;
mAudioRecord = new AudioRecord(mAudioSource, mSampleRate, mChannelCount, mAudioFomat, mBufferSize);
mAudioRecord.startRecording();
isRecording = true;
mRecordThead.start();
}
public void StopRecord()
{
if(isRecording)
{
isRecording = false;
}
}
이 코드로 통화음을 pcm 파일로 저장할려고 하는 데 야 1분 정도 녹음 하니 용량이 약 18GB 가 나옵니다.
변환 같은 거 하기 이전에 현재 모바일 개발인지라 도저히 저대로는 쓸 수가 없습니다.
파일 크기를 줄일 방법은 없습니까?
파일 크기를 줄인 다음에 mp3 파일로 변환 하고 싶은 데 좋은 방법이 있습니까?