开发者

real time audio recording and sending

I'm trying to capture audio from a microphone and no matter what buffer size (bufferSizeInBytes) I set at construct time of AudioRecord, when I do a AudioRecord.read I always get 8192 bytes of audio data (128 ms). I would like the AudioRecord.read be able to read 40ms of data (2560 bytes). The only working sample code that I can find is Sipdroid (RtpStreamSender.java) which I haven't tried. Here's the relevant piece of my code:

public void run()
{ 
running = true; 
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URG ENT_AUDIO); 
try { 
     frameSize = AudioRecord.getMinBufferSize(samplingRate, 
              AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); 
     Log.i(TAG, "trying to capture " + String.format("%d", frameSize) + " bytes"); 
     record = new AudioRecord(MediaRecorder.AudioSource.MIC, samplingRate, 
    AudioFormat.CHANNEL_CONFIGURATION_MONO, 开发者_运维百科AudioFormat.ENCODING_PCM_16BIT, frameSize);
     record.startRecording(); 
     byte[] buffer = new byte[frameSize]; 
     while (running)
     { 
        record.read(buffer, 0, frameSize); 
        Log.i(TAG, "Captured " + String.format("%d", frameSize) + " bytes of audio"); 
     } 
     record.stop(); 
     record.release(); 
 } catch (Throwable t) { 
 Log.e(TAG, "Failed to capture audio"); 
   } 
 }

My questions/comments are:

  1. Is this a limitation of AudioRecord class and/or the particular device ?
  2. I don't see a method to query the supported sampling rate (steps of bufferSizeInBytes) a given device can do. It would be nice if there's one.
  3. Can we use AudioRecord.OnRecordPositionUpdateListener and how?
  4. In above code encoding pcm in 8 bit is not working. why? if anyone tried sipdroid code, help me. Thanks in advance,
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜