gpt4 book ai didi

android - AudioRecord 文件大小有点大

转载 作者:行者123 更新时间:2023-11-29 01:11:38 28 4
gpt4 key购买 nike

我正在努力解决这个问题,我已经更改了比特率以减小录制文件的大小,我的应用程序正确地将音频文件发布到服务器,但我想最小化文件大小,这是我的录制代码

 private void startRecording() throws IOException {

String state = android.os.Environment.getExternalStorageState();
if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("No SD mounted. It is" + state
+ ".");

}

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setAudioSamplingRate(44100);
mRecorder.setAudioEncodingBitRate(44100);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);


File path = new File(Environment.getExternalStorageDirectory()
.getPath());

if (!path.exists() && !path.mkdirs()) {
throw new IOException("The file directory is invalid.");
}else{

try {
archivo = File.createTempFile("audio", ".3gp", path);
} catch (IOException e) {
}

}

mRecorder.setOutputFile(archivo.getAbsolutePath());
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);


try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}

mRecorder.start();


}

I am getting like 336 kb for 1 minute recording right now, I want to decrease it to around 100 - 200 kb per minute without loosing too much quality

最佳答案

您可以尝试一些事情。

1) 使用 AMR(自适应多速率)进行更高压缩:

recorder.setAudioEncoder(mRecorder.AudioEncoder.AMR_NB);

AMR Wideband 和 AMR Narrowband 是设备用于电话调用的编码方法。可能没有您需要的质量。

2) 使用单声道 1:

mRecorder.setAudioChannels (1)

// Sets the number of audio channels for recording. Call this method before
// prepare().
// Usually it is either 1 (mono) or 2 (stereo).

关于android - AudioRecord 文件大小有点大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42603364/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com