發表文章

目前顯示的是 2月, 2019的文章

Android AudioTrack AudioRecord II

上一篇寫一半,我們把他完善了,針對AudioRecord的部份 new Thread(new Runnable() {   @Override   public void run() {     int recBuffSize=AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);     //recBuffSize = 4096; //如果語音斷斷續續可以調整buffer size     AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, recBuffSize);                             byte[] buffer = new byte[recBuffSize];     audioRecord.startRecording(); // 开始录音     try {       clientSocket = new DatagramSocket();     } catch (SocketException e) {       e.printStackTrace();     }     InetAddress des = null;     try {       des = InetAddress.getByName("192.168.1.XX");     } catch (UnknownHostException e) {       e.printStackTrace();     }     int port = 3333;     while (true) {       int bufferReadResult = audioRecord.read(buffer, 0, recBuffSize);       packet = new DatagramPacket(buffer,