2012-03-28 98 views
1

我正在做一个在android的环回测试,使用AudioRecorder录制音频,然后将未压缩的pcm编码成speex,之后我将speex解码回pcm并发给AudioPlayer播放。后来我会在两台设备之间测试P2P。我试图记录音频,类似于通话录音,其中保存发送者和接收者无用的单一文件的MP4格式。任何人都可以建议我一个好的方向继续,也可以通过ffmpeg ported为android来实现这一点吗?如何在android中录制音频?

谢谢,

回答

4

我希望它会为你工作.. 设置路径在 “this.path = sanitizePath(路径);在这行”

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(); 
} 

}

+0

这将录制来自麦克风源的音频,即发送者语音但是,我从远程终端接收到的音频是否被路由到耳机,这是来自Speex数据的解码PCM,无论您的解决方案是否将录制的接收音频也记录在单个文件中?我更喜欢mp4a格式 – 2012-03-28 10:45:36

+0

我不能得到你正确的问题,请详细提及你想要什么,并在你的应用程序中执行@ newentry – pratik 2012-03-28 11:18:02

+0

必须将发送者和接收者音频记录到单个文件mp4a中,如前所述。 – 2012-03-28 11:37:24