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

89
LINES

< > BotCompany Repo | #1018656 // Audio Recordings + Set Words [Dyn Module]

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

Uses 12798K of libraries. Click here for Pure Java version (22167L/164K).

!7

set flag DynModule.

sclass Recording {
  File file, clippedFile;
  double length, clippedLength;
  S text, guess;
  
  *() {}
  *(File *file) {
    text = wordFromAudioFileName(file.getName());
    guess = getFileInfoField(file, 'Guess);
  }
  
  bool updateClip() {
    bool change = false;
    clippedFile = fileIfExists(fileInSubDir(file, "clipped"));
    if (length == 0) try {
      double l = lengthOfWAVInSeconds(file);
      if (l != 0) { length = l; set change; }
    } catch print e { length = -1; }
    if (clippedLength == 0) try {
      double l = lengthOfWAVInSeconds(clippedFile);
      if (l != 0) { clippedLength = l; set change; }
    } catch print e { clippedLength = -1; }
    ret change;
  }
}

sclass AudioRecordings 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",
        "Clipped length" := r.clippedLength == 0 ? "" : formatDouble(r.clippedLength, 1) + " s",
        Word := r.text,
        Guess := r.guess)
    };
    ownResource(vmBus_onMessage('newRecording, scan));
    scan.trigger();
  }
  
  void _scan {
    temp enter();
    setData(map(latestFilesFirst(allRecordings()), func(File f) -> Recording {
      Recording(f)
    }));
    
    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 full", rThread { dm_playWAV(selected().file) }),
      tableDependentButton(table, "Show & set markers", rThread { showAudioFileWithEditableMarkers(selected().file) }),
      tableDependentButton(table, "Play clipped", rThread { dm_playWAV(selected().clippedFile) }),
      tableDependentButton(table, "Show clipped", rThread { showFrequencyImage(selected().clippedFile) }),
      tableDependentButton(table, "Set word...", rThread {
        final Recording r = selected();
        inputText("Word spoken in " + r.file.getName(), voidfunc(S word) {
          File newFile = makeFileNameUnique_space(recordingsDir(word + ".wav"));
          renameRecordingAndClipAndGuess(r.file, newFile.getName());
          Recording r2 = new(newFile);
          r2.updateClip();
          syncReplace(data, r, r2);
          updateTable();
        });
      }),
    );
  }
}

Author comment

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: 356 / 2854
Version history: 30 change(s)
Referenced in: [show references]