录出来之后全是噪音int frequency = 8000;
int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/reverseme.pcm");
.... OutputStream os = new FileOutputStream(file);
            BufferedOutputStream bos = new BufferedOutputStream(os);
            DataOutputStream dos = new DataOutputStream(bos);
             
            // Create a new AudioRecord object to record the audio.
            int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration,  audioEncoding);
            AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency, channelConfiguration, audioEncoding, bufferSize);
            
            short[] buffer = new short[bufferSize];   
            audioRecord.startRecording();
            int nCount = 1;
            
            while(nCount<21)
            {
            int bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
            Log.i("550", Integer.toString(bufferReadResult));
            
            for (int i = 0; i < bufferReadResult; i++)
            {
             dos.writeShort(buffer[i]);
             Log.i("540", "123");
            }
            nCount++;
            }
            audioRecord.stop();
            dos.close();

解决方案 »

  1.   

    看看这个能帮助你么http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=10365
      

  2.   

    是真机,HTC的Desire G7的一个机子
      

  3.   

    1. 参数没对
    2. 要看机器的,有的机器不支持某些参数
    以前在WM上面做了一个mp3编码的程序就是,通过麦克风录音,同一份代码设置相同的码率,比特率,单双声道在不同的机器上面表现完全不一样,其中一台录制出来效果非常好,另外一个就全是杂音.
      

  4.   

    我建议你用你的程序录一首歌
    然后去下一个声音分析软件,看一下你录制出来的这个歌的波形和源文件那首歌的波形差别是不是很大,如果你参数设置的比较大,大概在32000hz, 16bit, 双声道的话,波形应该差不多的,如果你参数设错了,波形相差很大,一眼就看出来了
      

  5.   

    这是我写的,可用,你试一下吧
    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
         };
      

  6.   

    private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 };
    public static final String TAG = "find";
    public AudioRecord findAudioRecord() {
        for (int rate : mSampleRates) {
            for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT }) {
                for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO }) {
                    try {
                        Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "
                                + channelConfig);
                        int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);                     if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
                            // check if we can instantiate and have a success
                            AudioRecord recorder = new AudioRecord(AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);                         if (recorder.getState() == AudioRecord.STATE_INITIALIZED)
                                return recorder;
                        }
                    } catch (Exception e) {
                        Log.e(TAG, rate + "Exception, keep trying.",e);
                    }
                }
            }
        }
        return null;
    }