问题描述
我想以纯音频格式录制语音.目前我正在使用此代码
I want to record voice in pure audio format.currently I am using this code
public static void startRecording(String fileName) {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
String mFileName = Environment.getExternalStorageDirectory()
.getAbsolutePath();
mFileName += "/abc.mp3";
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
mRecorder.start();
} catch (IOException e) {
Log.e(TAG, "prepare() failed");
}
}
这显示文件为mp3,但内部文件内容的mime类型为"video/mp4".我需要的是任何音频哑剧类型.
This is showing the file as mp3 but the internal file content mime type is "video/mp4". What I need is any audio mime type.
EDIT1 根据 Headuck 的建议,我将代码更改为
EDIT1As suggested by Headuck, I changed my code to
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mFileName += "/abc.aac";
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
使用"audio/x-hx-aac-adts" mime类型可以完美地录制音频.谢谢 Headuck .
The audio got recorded perfectly with "audio/x-hx-aac-adts" mime type. Thanks Headuck.
但是我的问题是:
我正在使用Cloud端点将此文件上传到Google云端硬盘.然后,当我打开文件时,它说糟糕!!!播放此文件时出现问题".我需要在播放"MP3"文件时播放该文件.
I am uploading this file to Google Drive using Cloud endpoints. Then when I open the file it is saying "Oops..! There was a problem in playing this file". I need the file to be played as "MP3" files play.
Google云端硬盘是否支持"ACC"格式?如果没有,请提出替代方案.
请帮忙.
Does Google Drive supports "ACC" format?. If not please suggest alternatives.
Please help.
推荐答案
如果只需要将mime类型更改为audio
类型,则可以在记录器的stop()
和release()
之后尝试以下操作(为清楚起见,省略了try-catch块):
If all you need is to change the mime type to an audio
one, you may try the following after stop()
and release()
of the recorder (try-catch blocks omitted for clarity):
mRecorder.stop();
mRecorder.release();
// Set the mime type to audio
String[] paths = {mFileName};
String[] mimeTypes = {"audio/mp4"};
MediaScannerConnection.scanFile(getApplicationContext(),
paths,
mimeTypes,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
System.out.println("SCAN COMPLETED: " + path);
}
});
这篇关于如何在Android中使用Audio MimeType录制语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!