簡體   English   中英

如何在android中錄制音頻?

[英]How to record audio in android?

我在android中進行環回測試,使用AudioRecorder錄制音頻,然后將未壓縮的pcm編碼為speex,之后我將speex解碼回pcm並發送給AudioPlayer進行播放。后來我將測試兩個設備之間的P2P。 我正在嘗試錄制音頻,類似於通話記錄,其中將發送者和接收者的聲音保存為單個文件mp4格式。任何人都建議我繼續前進的良方向,也可以通過移植到Android的ffmpeg來實現這一點嗎?

謝謝,

我希望它能為你工作..在“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();
 }

}

MediaRecorder.AudioSource是一個好的開始,我猜?

http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM