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

75
LINES

< > BotCompany Repo | #1019278 // Mark Recordings as Voice/Non-Voice [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 12716K of libraries. Click here for Pure Java version (7935L/40K).

!7

set flag DynModule.

sclass Recording {
  File file;
  double length;
  S containsVoice;
  
  *() {}
  *(File *file) {
    containsVoice = getFileInfoField(file, "Contains voice");
  }
  
  bool updateClip() {
    bool change = false;
    if (length == 0) try {
      double l = lengthOfWAVInSeconds(file);
      if (l != 0) { length = l; set change; }
    } catch print e { length = -1; }
    ret change;
  }
}

cmodule AudioRecordings2 extends DynObjectTable<Recording> {
  transient ReliableSingleThread scan = dm_rst(this, r _scan);
  
  start {
    itemToMap = func(Recording r) -> Map {
      litorderedmap(
        Name := fileName(r.file),
        "Length" := formatDouble(r.length, 1) + " s",
        "Contains Voice" := or2(r.containsVoice, "?"))
    };
    ownResource(vmBus_onMessage('newRecording, scan));
    scan.trigger();
  }
  
  void _scan {
    temp enter();
    setData(map(latestFilesFirst(allRecordings()), f1_new(Recording)));
    
    thread "Get Clip Lengths" {
      bool change = false;
      for (Recording r : data)
        if (r.updateClip()) set change;
      if (change) updateTable();
    }
  }
  
  visualize {
    JComponent c = super.visualize();
    ret withCenteredButtons(c,
      tableDependentButton(table, "Clip", rThread {
        File f = selected().file;
        //autoClipRecording(f);
        clipWAVFromMarkers(f, fileInSubDir(f, "clipped"));
        selected().updateClip();
        updateTable();
      }),
      tableDependentButton(table, "Copy path", rThread { copyTextToClipboard(f2s(selected().file)) }),
      tableDependentButton(table, "Play", rThread { dm_playWAV(selected().file) }),
      tableDependentButton(table, "Has voice", rThread {
        final Recording r = selected();
        setFileInfoField(r.file, "Contains voice", "Yes");
        updateTable();
      }),
      tableDependentButton(table, "No voice", rThread {
        final Recording r = selected();
        setFileInfoField(r.file, "Contains voice", "No");
        updateTable();
      }),
    );
  }
}

Author comment

Began life as a copy of #1018656

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1019278
Snippet name: Mark Recordings as Voice/Non-Voice [Dyn Module]
Eternal ID of this version: #1019278/4
Text MD5: fa0994fe3bef2d1d1cadd83c5edc0511
Transpilation MD5: 46e1d0133c4d975aade432e09ca75e57
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: 2020-02-04 01:48:18
Source code size: 2111 bytes / 75 lines
Pitched / IR pitched: No / No
Views / Downloads: 251 / 1193
Version history: 3 change(s)
Referenced in: [show references]