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

29
LINES

< > BotCompany Repo | #1007035 // Capture Audio By Button Press [dev.]

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

Uses 3874K of libraries. Click here for Pure Java version (3464L/23K/83K).

1  
!7
2  
3  
static JButton button;
4  
static volatile Capturer cap;
5  
static File wavFile;
6  
7  
p-substance {
8  
  showControls(jCenteredLine(button = jbutton("Record!", f recordOrStop)));
9  
}
10  
11  
svoid recordOrStop {
12  
  if (cap != null) {
13  
    cap.stop();
14  
    byte[] pcm = cap.getPCM();
15  
    infoMessage("Got " + l(pcm) + " bytes PCM!");
16  
    pcmToWAVE(pcm, cap.format(), wavFile);
17  
    infoBox("Wrote " + f2s(wavFile) + " (" + wavFile.length() + " bytes)");
18  
    cap = null;
19  
    setText(button, "Record!");
20  
  } else {
21  
    AudioLine line = first(allTargetDataLines());
22  
    assertNotNull("Need audio input line!", line);
23  
    DataLine dataLine = cast line.open();
24  
    print("Capturing");
25  
    wavFile = prepareProgramFile(ymd_minus_hms() + ".wav");
26  
    cap = captureAudioFromLine2(dataLine, sphinxAudioFormat());
27  
    setText(button, "Stop");
28  
  }
29  
}

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: #1007035
Snippet name: Capture Audio By Button Press [dev.]
Eternal ID of this version: #1007035/6
Text MD5: 14dc49d717e9767f35697504e44c90c1
Transpilation MD5: 6371229cf88acc9138f0fbb56298d978
Author: stefan
Category: javax / audio
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-26 00:15:08
Source code size: 842 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 460 / 550
Version history: 5 change(s)
Referenced in: [show references]