マイクからのサウンドを録音し、サウンドを .pcm ファイルに保存するプログラムがあります。
プログラムには、MediaCodec と MediaMuxer を使用して .pcm を aac に変換する別の関数があります。
MediaCodec を使用して .pcm を aac に直接変換するようにプログラムを変更することはできますか?どうすればよいですか? ガイドはありますか、それを行うためのコードサンプルはありますか?
これは、マイクからの音を録音する私のプログラムのコード スニペットです。
recorder = new AudioRecord(
MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE,
RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING,
bufferSize);
recorder.startRecording();
isRecording = true;
FileOutputStream os = null;
try {
os = new FileOutputStream(filePathAudioRec);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (isRecording) {
// gets the voice output from microphone to byte format
recorder.read(sData, 0, BufferElements2Rec);
try {
// writes the data to file from buffer
// stores the voice buffer
byte bData[] = short2byte(sData);
os.write(bData, 0, BufferElements2Rec * BytesPerElement); //do I need to write it to a file ??
} catch (IOException e) {
e.printStackTrace();
}
// inside while loop: add code to convert to .mp4 while the data is collected from the MIC
}