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).

1  
!7
2  
3  
import javax.sound.sampled.*;
4  
5  
p-tt {
6  
  //AudioFormat format = new AudioFormat(8000.0f, 16, 1, true, true);
7  
  AudioFormat format = new AudioFormat(8000.0f, 8, 1, true, true);
8  
  TargetDataLine microphone;
9  
  microphone = AudioSystem.getTargetDataLine(format);
10  
11  
  DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
12  
  microphone = (TargetDataLine) AudioSystem.getLine(info);
13  
  microphone.open(format);
14  
15  
  ByteArrayOutputStream out = new ByteArrayOutputStream();
16  
  int numBytesRead;
17  
  int bufSize = microphone.getBufferSize();
18  
  print("Mic buffer size: " + bufSize);
19  
  byte[] data = new byte[bufSize/5];
20  
  microphone.start();
21  
22  
  int bytesRead =0;
23  
24  
  while (bytesRead < 10000) { //Just so I can test if recording my mic works...
25  
    numBytesRead = microphone.read(data, 0, data.length);
26  
    bytesRead += numBytesRead;
27  
    print("Bytes: " + bytesRead);
28  
    out.write(data, 0, numBytesRead);
29  
  }
30  
  microphone.close();
31  
  psl(splitArrayRegularly(out.toByteArray(), 32));
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: 603 / 1271
Version history: 11 change(s)
Referenced in: [show references]