我想在android中制作电话录音机。我有以下代码,当我使用时 MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK 正在录制通话但播放时无法理解。如果对 AudioSouce.MIC 使用相同的代码 那么录制的文件是可以理解的。 这是我的代码
package com.example.callrecoder;
import java.io.File;
import java.io.IOException;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button record_call = (Button)this.findViewById(R.id.record);
final Button stop_recorder = (Button)this.findViewById(R.id.stop);
final MediaRecorder _recorder = new MediaRecorder();
record_call.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//MediaRecorder _recorder = new MediaRecorder();
try {
String state = android.os.Environment.getExternalStorageState();
/* if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state
+ ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/sam.wav").getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}*/
//_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL );
_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK );
_recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
//_recorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
// + "/test.wav");
_recorder.setOutputFile("/sdcard/sample.3GPP");
_recorder.prepare();
_recorder.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
stop_recorder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
_recorder.stop();
_recorder.reset();
_recorder.release();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
//_recorder = null;
}
});
}
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
我想用AudioSource.downlink和上传记录电话。 PLZ帮我解决了这个问题。我在Samsang Galaxay Gio手机上测试它。
答案 0 :(得分:1)
Insted of VOICE_CALL使用VOICE_RECOGNITION ,,,
callRecorder = new MediaRecorder();
callRecorder.reset();
callRecorder.setAudioSamplingRate(8000);
callRecorder.setAudioEncodingBitRate(12200);
callRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
callRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
callRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);