Uses 12798K of libraries. Click here for Pure Java version (22167L/164K).
1 | !7 |
2 | |
3 | set flag DynModule. |
4 | |
5 | sclass Recording { |
6 | File file, clippedFile; |
7 | double length, clippedLength; |
8 | S text, guess; |
9 | |
10 | *() {} |
11 | *(File *file) { |
12 | text = wordFromAudioFileName(file.getName()); |
13 | guess = getFileInfoField(file, 'Guess); |
14 | } |
15 | |
16 | bool updateClip() { |
17 | bool change = false; |
18 | clippedFile = fileIfExists(fileInSubDir(file, "clipped")); |
19 | if (length == 0) try { |
20 | double l = lengthOfWAVInSeconds(file); |
21 | if (l != 0) { length = l; set change; } |
22 | } catch print e { length = -1; } |
23 | if (clippedLength == 0) try { |
24 | double l = lengthOfWAVInSeconds(clippedFile); |
25 | if (l != 0) { clippedLength = l; set change; } |
26 | } catch print e { clippedLength = -1; } |
27 | ret change; |
28 | } |
29 | } |
30 | |
31 | sclass AudioRecordings extends DynObjectTable<Recording> { |
32 | transient ReliableSingleThread scan = dm_rst(this, r _scan); |
33 | |
34 | start { |
35 | itemToMap = func(Recording r) -> Map { |
36 | litorderedmap( |
37 | Name := fileName(r.file), |
38 | "Length" := formatDouble(r.length, 1) + " s", |
39 | "Clipped length" := r.clippedLength == 0 ? "" : formatDouble(r.clippedLength, 1) + " s", |
40 | Word := r.text, |
41 | Guess := r.guess) |
42 | }; |
43 | ownResource(vmBus_onMessage('newRecording, scan)); |
44 | scan.trigger(); |
45 | } |
46 | |
47 | void _scan { |
48 | temp enter(); |
49 | setData(map(latestFilesFirst(allRecordings()), func(File f) -> Recording { |
50 | Recording(f) |
51 | })); |
52 | |
53 | thread "Get Clip Lengths" { |
54 | bool change = false; |
55 | for (Recording r : data) |
56 | if (r.updateClip()) set change; |
57 | if (change) updateTable(); |
58 | } |
59 | } |
60 | |
61 | visualize { |
62 | JComponent c = super.visualize(); |
63 | ret withCenteredButtons(c, |
64 | tableDependentButton(table, "Clip", rThread { |
65 | File f = selected().file; |
66 | //autoClipRecording(f); |
67 | clipWAVFromMarkers(f, fileInSubDir(f, "clipped")); |
68 | selected().updateClip(); |
69 | updateTable(); |
70 | }), |
71 | tableDependentButton(table, "Copy path", rThread { copyTextToClipboard(f2s(selected().file)) }), |
72 | tableDependentButton(table, "Play full", rThread { dm_playWAV(selected().file) }), |
73 | tableDependentButton(table, "Show & set markers", rThread { showAudioFileWithEditableMarkers(selected().file) }), |
74 | tableDependentButton(table, "Play clipped", rThread { dm_playWAV(selected().clippedFile) }), |
75 | tableDependentButton(table, "Show clipped", rThread { showFrequencyImage(selected().clippedFile) }), |
76 | tableDependentButton(table, "Set word...", rThread { |
77 | final Recording r = selected(); |
78 | inputText("Word spoken in " + r.file.getName(), voidfunc(S word) { |
79 | File newFile = makeFileNameUnique_space(recordingsDir(word + ".wav")); |
80 | renameRecordingAndClipAndGuess(r.file, newFile.getName()); |
81 | Recording r2 = new(newFile); |
82 | r2.updateClip(); |
83 | syncReplace(data, r, r2); |
84 | updateTable(); |
85 | }); |
86 | }), |
87 | ); |
88 | } |
89 | } |
Began life as a copy of #1018469
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1018656 |
Snippet name: | Audio Recordings + Set Words [Dyn Module] |
Eternal ID of this version: | #1018656/31 |
Text MD5: | a95cf805e8e7141c2acf0d1525156836 |
Transpilation MD5: | 31ac0ef526fc2d6745176c0b19f4a028 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-29 11:22:38 |
Source code size: | 2982 bytes / 89 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 445 / 2965 |
Version history: | 30 change(s) |
Referenced in: | [show references] |