Uses 1258K of libraries. Click here for Pure Java version (5582L/28K).
!7 cmodule ConcurrentMP3 > DynPrintLogAndEnabled { transient StreamingMP3Encoder encoder; switchable int bitRate = 64; start { dm_vmBus_onMessage_q startedRecording((IVF1<File>) lambda1 started); dm_vmBus_onMessage_q recordedChunk((IVF1<short[]>) lambda1 gotChunk); dm_vmBus_onMessage_q doneRecording(r done); } void cleanMeUp { dispose encoder; } void started(File wavFileBeingMade) { if (!enabled) ret; File mp3 = changeExtension(wavFileBeingMade, ".live.mp3"); float sampleRate = dm_audioInputSampleRate(); int channels = dm_audioInputChannels(); print("started MP3 encoding: " + mp3 + " at " + sampleRate + " Hz" + " (" + nChannels(channels) + ")"); encoder = new StreamingMP3Encoder; encoder.mp3 = mp3; encoder.format = javaSound_pcmSignedLittleEndian(sampleRate, channels); encoder.bitRate = bitRate; encoder.init(); vmBus_send startedRecordingMP3(mp3); encoder.onBytesWritten = (array, i, j) -> vmBus_send wroteMP3Chunk(mp3, array, i, j); } void gotChunk(short[] samples) { //print("got " + nSamples(samples)); if (enabled && encoder != null) encoder.addData(samples); } void done { if (encoder == null) ret; File mp3 = encoder.mp3; dispose encoder; vmBus_send newMP3Recording(mp3); print("Wrote " + fileInfo(mp3)); } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026970 |
Snippet name: | Concurrent MP3 Encoding [still only works with mono audio input] |
Eternal ID of this version: | #1026970/23 |
Text MD5: | b52d8c0001743a4465e5a48f6e98ce04 |
Transpilation MD5: | 7182c087febfa5b52bdcc221ffc9eb9d |
Author: | stefan |
Category: | javax / audio |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-17 16:26:39 |
Source code size: | 1391 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 304 / 13392 |
Version history: | 22 change(s) |
Referenced in: | #1026972 - Recognize Last Recording As English Speech With Wit.AI [Concurrent MP3 Encoding Version] #1026978 - DynWitAILastRecording - Recognize Last Recording With Wit.AI [Fully Pipelined Version] |