0
AudioRecord 클래스를 사용하여 .mp3 형식으로 오디오를 녹음하고 저장하려고합니다. 현재 .pcm 형식으로 녹음 중입니다. 아래 코드를 기록 용으로 사용했습니다. -AudioRecord를 사용하여 .mp3 형식의 오디오 녹음
private void writeAudioDataToFile() {
// Write the output audio in byte
String filePath = "/sdcard/voice8K16bitmono.pcm";
short sData[] = new short[BufferElements2Rec];
FileOutputStream os = null;
try {
os = new FileOutputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (isRecording) {
// gets the voice output from microphone to byte format
m_audioRecord.read(sData, 0, BufferElements2Rec);
System.out.println("Short wirting to file" + sData.toString());
try {
// // writes the data to file from buffer
// // stores the voice buffer
byte bData[] = short2byte(sData);
os.write(bData, 0, BufferElements2Rec * BytesPerElement);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private byte[] short2byte(short[] sData) {
int shortArrsize = sData.length;
byte[] bytes = new byte[shortArrsize * 2];
for (int i = 0; i < shortArrsize; i++) {
bytes[i * 2] = (byte) (sData[i] & 0x00FF);
bytes[(i * 2) + 1] = (byte) (sData[i] >> 8);
sData[i] = 0;
}
return bytes;
}
위의 두 가지 방법은 파일을 .pcm 형식으로 기록하는 것입니다. AudioRecord 클래스를 사용하여 오디오를 .mp3 형식으로 저장할 수 있습니까?
여기에 코드를 입력하십시오. –
코드 –
을 추가했습니다. 자동 통화 녹음을 녹음 하시겠습니까? –