Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1006992 // Desktop: Test recording audio [seems to work]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1893L/13K).

!7

import javax.sound.sampled.*;

p-tt {
  //AudioFormat format = new AudioFormat(8000.0f, 16, 1, true, true);
  AudioFormat format = new AudioFormat(8000.0f, 8, 1, true, true);
  TargetDataLine microphone;
  microphone = AudioSystem.getTargetDataLine(format);

  DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
  microphone = (TargetDataLine) AudioSystem.getLine(info);
  microphone.open(format);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int numBytesRead;
  int bufSize = microphone.getBufferSize();
  print("Mic buffer size: " + bufSize);
  byte[] data = new byte[bufSize/5];
  microphone.start();

  int bytesRead =0;

  while (bytesRead < 10000) { //Just so I can test if recording my mic works...
    numBytesRead = microphone.read(data, 0, data.length);
    bytesRead += numBytesRead;
    print("Bytes: " + bytesRead);
    out.write(data, 0, numBytesRead);
  }
  microphone.close();
  psl(splitArrayRegularly(out.toByteArray(), 32));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006992
Snippet name: Desktop: Test recording audio [seems to work]
Eternal ID of this version: #1006992/12
Text MD5: 639962b3dc2fc7c14bebd5f41ac196d0
Transpilation MD5: 6b8a19c49d5096480fa82f77405a146e
Author: stefan
Category: javax / audio
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-12 14:18:10
Source code size: 1016 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 433 / 898
Version history: 11 change(s)
Referenced in: [show references]