2014-10-06 81 views

回答

0

運行一個後臺線程,並使用下面的代碼MediaRecorder錄製音頻,有助於記錄的背景語音呼叫,並將其寫入文件到SD卡

private void startRecording() { 
     filePath = getFilename(); 
     recorder = new MediaRecorder(); 
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); 
     recorder.setOutputFile(filePath); 
     recorder.setOnErrorListener(errorListener); 
     recorder.setOnInfoListener(infoListener); 
     recorder.getMaxAmplitude(); 

     try { 
      if (recorder != null) { 
       recorder.prepare(); 
       recorder.start(); 
      } 

     } catch (IllegalStateException e) { 
      Log.d(LOG_TAG, e.toString()); 
     } catch (IOException e) { 
     } catch (Exception e) { 
      Log.d(LOG_TAG, e.toString()); 
     } 
    } 

    private String getFilename() { 
     File filepath = Environment.getExternalStorageDirectory(); 
     File dir = new File(filepath.getAbsolutePath() 
       + "/Android"); 
     if (!dir.exists()) { 
      dir.mkdirs(); 
     } 
     String uriSting = (dir.getAbsolutePath() + "/" 
       + System.currentTimeMillis() + ".mp3"); 

     return uriSting; 

    } 
+0

我想改變音高。我已經錄製了音頻。 – 2014-10-07 05:28:33

+0

檢查此鏈接http://stackoverflow.com/questions/5156192/programmatically-increase-the-pitch-of-an-array-of-audio-samples – rajahsekar 2014-10-08 04:44:20