我在使用Android的MediaRecorder录制麦克风声音到.m4a文件(AAC-LC,MPEG-4容器)时遇到了问题。从API 18开始,默认采样率从44.1或48 kHz(取决于设备)降至仅8 Hz。如果我使用MediaRecorder.setAudioSamplingRate指定采样率,则会使用指定的采样率,但录音中会出现很多奇怪的噪音。
在LogCat中,有时会发生以下警告:
(1) 标签:AudioSource 文本:AudioRecord报告溢出
(2) 标签:AudioFlinger 文本:RecordThread:缓冲区溢出
以下是代码:
在LogCat中,有时会发生以下警告:
(1) 标签:AudioSource 文本:AudioRecord报告溢出
(2) 标签:AudioFlinger 文本:RecordThread:缓冲区溢出
以下是代码:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioChannels(2);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioSamplingRate(48000); // if not specified, defaults to 8kHz, if specified 44.1 or 48 kHz, lots of noise
recorder.setOutputFile("test.m4a");
try {
recorder.prepare();
recorder.start();
} catch (IOException ioe) {
Log.e(TAG, "IOException", ioe);
} catch (IllegalStateException ise) {
Log.e(TAG, "IllegalStateException", ise);
} catch (Exception e) {
Log.e(TAG, "Exception", e);
}
非常感谢您的帮助。
setAudioEncodingBitRate(...)
进行实验吗? - Squonk