audiorecord录音

private Runnable threadStartRec = new Runnable()
   {

public void run() {
// TODO Auto-generated method stub

  
  //start record
   int minBuffSize = AudioRecord.getMinBufferSize(8000,
   AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);
AudioRecord mAudioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
// AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBuffSize*3);
mAudioRecorder.startRecording();

   byte[] mBuffer = new byte[minBuffSize*3];

   int len = 0;
   File fw = new File ( strFileName ); 
  FileOutputStream fisWriter = null;
    
  try {
fw.createNewFile();
fisWriter = new FileOutputStream (fw);
   //FileInputStream fisReader = new FileInputStream (fw);

   }
catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
  
  while(bRecording)
   {
   len = 0;
   len = mAudioRecorder.read(mBuffer, 0, minBuffSize);
   //write into file
   // if(len>0&&len<=minBuffSize)
   {
   //
   try {
fisWriter.write(mBuffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   }
   try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
   }//end of while
   try {
fisWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//end of Run
   };

你可能感兴趣的:(thread)