Uses 911K of libraries. Click here for Pure Java version (6250L/31K).
1 | !7 |
2 | |
3 | import javax.sound.sampled.*; |
4 | |
5 | cmodule AudioInputFromPhone > DynPrintLog { |
6 | switchable int sampleRate = 16000; |
7 | switchable int channels = 1; |
8 | switchable int bufSize = 8192; |
9 | switchable bool sendOutClonedData; // makes things easier for clients |
10 | switchable bool verbose; |
11 | transient AudioInputDispatcher loop; |
12 | transient SimpleLiveValue<Float> lvVolume = floatLiveValue(); // in percent |
13 | transient L<VF1<short[]>> audioListeners = synchroList(); |
14 | |
15 | visual centerAndSouthWithMargins(super.visualize(), |
16 | jCenteredLine(jLiveValueLabel(mapLiveValue(func(float volume) -> S { "Volume: " + iround(volume) + " %" }, S, lvVolume)))); |
17 | |
18 | start { |
19 | loop = new AudioInputDispatcher(bufSize); |
20 | loop.audioListeners = audioListeners; |
21 | loop.lvVolume = lvVolume; |
22 | loop.verbose = verbose; |
23 | dm_watchFieldAndNow sendOutClonedData(() -> { loop.cloneDataOnce = sendOutClonedData; }); |
24 | dm_vmBus_onMessage oic_gotLine(voidfunc(O module, S line, O socket, O state) enter { |
25 | if (startsWith(line, "audio: ")) { |
26 | //print("Have audio line"); |
27 | byte[] data = base64decode(substring(line, l("audio: "))); |
28 | dm_q(r { |
29 | loop.handleData(data); |
30 | }); |
31 | } |
32 | }); |
33 | dm_registerAs audioInputModule(); |
34 | JComponent trayIcon = jMinWidth(16, jVerticalGreenBar(lvVolume, max := 100)); |
35 | componentPopupMenuItem(trayIcon, "Audio Input", r { dm_showModule(module()) }); |
36 | dm_setTrayIcon(trayIcon); |
37 | } |
38 | |
39 | // hold audio listeners during reload |
40 | |
41 | O _getReloadData() { ret audioListeners; } |
42 | void _setReloadData(L<VF1<short[]>> listeners) { addAll(audioListeners, listeners); } |
43 | |
44 | // API |
45 | |
46 | void addAudioListener(VF1<short[]> l) { audioListeners.add(l); } |
47 | void removeAudioListener(VF1<short[]> l) { audioListeners.remove(l); } |
48 | |
49 | AudioFormat getAudioFormat() { ret new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, 16, channels, channels*2, sampleRate, false); } |
50 | |
51 | float getVolume() { ret lvVolume!; } |
52 | |
53 | // for debugging |
54 | O currentListener() { ret loop.currentListener; } |
55 | } |
Began life as a copy of #1017138
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: | #1027053 |
Snippet name: | Audio Input From Phone [OK] |
Eternal ID of this version: | #1027053/8 |
Text MD5: | d77ee3e2da7d4ef4b00fe0dd2bc58940 |
Transpilation MD5: | 704e3073a14fb2c035b518dbf59b06f0 |
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-15 14:31:39 |
Source code size: | 2093 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 318 / 526 |
Version history: | 7 change(s) |
Referenced in: | [show references] |