我在android中进行环回测试,使用AudioRecorder录制音频,然后将未压缩的pcm编码为speex,之后我将speex解码回pcm并发送给AudioPlayer进行播放。后来我将测试两个设备之间的P2P。我正在尝试录制音频,类似于通话记录,其中将发送者和接收者的声音保存为单个文件mp4格式。任何人都建议我继续前进的良方向,也可以通过ffmpeg移植到Android来实现这一点吗? / p>
感谢,
答案 0 :(得分:4)
我希望它对你有用.. 在“this.path = sanitizePath(path);在此行”
中设置路径 public class AudioRecorder
{
final MediaRecorder recorder=new MediaRecorder();
final String path;
public AudioRecorder(String path)
{
this.path = sanitizePath(path);
}
private String sanitizePath(String path)
{
if (!path.startsWith("/"))
{
path = "/" + path;
}
if (!path.contains("."))
{
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
public void start() throws IOException
{
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 + ".");
}
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs())
{
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
}
public void stop() throws IOException
{
recorder.stop();
recorder.release();
}
}
答案 1 :(得分:0)
我认为MediaRecorder.AudioSource是一个好的开始吗?
http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html