简体   繁体   English

在android中用于存储录制的音频格式

[英]which audio format to use in android to store recording

I am developing application which records voice from mic, currently I am storing recorded audio in wave file but size of wave is becoming an issue. 我正在开发从麦克风录制语音的应用程序,目前我将录制的音频存储在wave文件中,但是wave的大小正成为一个问题。

I came to know that android do not have mp3 decoder is it true? 我才知道android没有mp3解码器是真的吗? What would I do to store recorded audio in compressed form? 如何以压缩形式存储录制的音频?

I am using AudioRecord class for recording and don't want to use MediaRecorder. 我使用AudioRecord类进行录制,不想使用MediaRecorder。

Using AudioRecord does not give you many options. 使用AudioRecord并没有给你很多选择。 It stores audio in PCM format only. 它仅以PCM格式存储音频。 You can lower size only by setting channel config to CHANNEL_IN_MONO and audio format to ENCODING_PCM_8BIT. 您只能通过将通道配置设置为CHANNEL_IN_MONO并将音频格式设置为ENCODING_PCM_8BIT来降低尺寸。 Additionally, you can try to extend AudioRecord class and override read() method. 此外,您可以尝试扩展AudioRecord类并覆盖read()方法。 Then you must convert audio yourself but that's not recommended. 然后你必须自己转换音频,但不建议这样做。

I know you don't want this but the best option would be refactoring your code to use MediaRecorder. 我知道你不想要这个,但最好的选择是重构你的代码以使用MediaRecorder。 Here is example from reference documentation: 以下是参考文档中的示例:

MediaRecorder recorder = new MediaRecorder();
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(PATH_NAME);
 recorder.prepare();
 recorder.start();   // Recording is now started
 ...
 recorder.stop();
 recorder.reset();   // You can reuse the object by going back to setAudioSource() step
 recorder.release(); // Now the object cannot be reused

On this site http://developer.android.com/guide/appendix/media-formats.html#core you have nice table presenting all supported formats taking into considerations Android versions. 在这个网站http://developer.android.com/guide/appendix/media-formats.html#core上,你有一个很好的表格,展示考虑到Android版本的所有支持的格式。 Try these AAC LC, AMR-NB, AMR-WB. 试试这些AAC LC,AMR-NB,AMR-WB。 Except sizes check the quality. 除尺寸外,检查质量。

There is no Mp3 decoder but the default format which all android version will support is .mgp and .amr format which will be played using MediaPlayer and AudioPlayer classes by default 没有Mp3解码器,但所有Android版本都支持的默认格式是.mgp和.amr格式,默认情况下将使用MediaPlayer和AudioPlayer类播放

Note : This is not guarantee that all the players will support this extension , if it is not an android device 注意 :如果不是Android设备,这并不保证所有播放器都支持此扩展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM