2017-06-20 172 views
-1

我想知道是否可以從手機的麥克風錄製語音並同時播放它?錄製音頻並同時播放

private void ditchMediaplayer(){ 
     if (mediaRecorder!=null)mediaRecorder.release(); 
     try 
     { 
     mediaPlayer.release(); 
     }catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 

     private void beginRecording()throws IOException 
     { 
      ditchMediaplayer(); 

      if (outFile.exists()) 
      { 
       outFile.delete(); 
      } 
      mediaRecorder=new MediaRecorder(); 
      mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
      mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
      mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
      mediaRecorder.setOutputFile(OUTPUT_FILE); 
      mediaRecorder.prepare(); 
      mediaRecorder.start(); 
     } 

     private void stopRecording() 
     { 
     if (mediaRecorder !=null) 
     { 
       mediaRecorder.stop(); 
     } 
     } 

所以我需要使用mediaplayer.play();?但我不知道我可以在哪裏工作。

我的目標是流出我的聲音,但我不想記錄我的聲音然後播放它。我希望我的聲音能夠同時錄製和播放。

感謝您的幫助!

+1

你必須完成錄製到從我所知道玩。你應該爲你的目的使用一個流光盤,我相信 – 2017-06-20 08:11:24

回答

1

錄製的音頻文件(簡版)

目的。記錄音頻數據並將其存儲在一個文件中。數據以CD質量(44.1 kHz,16位線性,立體聲)記錄並存儲在.wav文件中。

用法。

java SimpleAudioRecorder -h 

java SimpleAudioRecorder audiofile 

參數。

-h 

打印使用信息,然後退出

audiofile 

應當從記錄的數據

錯誤,限制生產的音頻文件的文件名。您不能在命令行上選擇音頻格式和音頻文件類型。有關更高級選項的版本,請參閱AudioRecorder。由於Sun jdk1.3/1.4中存在一個錯誤,該程序無法使用。

源代碼。http://www.jsresources.org/examples/SimpleAudioRecorder.java.html

你應該閱讀它可能會幫助 - http://www.jsresources.org/examples/audio_playing_recording.html

+0

也許「立即錄製和回放錄製的數據」這部分會幫助我很多! – Unknown1994