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

37
LINES

< > BotCompany Repo | #1027542 // Audio Feedback Preventer [OK, stops speech output -> recognition endless loops]

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

Uses 911K of libraries. Click here for Pure Java version (5210L/26K).

!7

// Goes well with a headphone detector like #1027532

cmodule AudioFeedbackPreventer > DynPrintLogAndEnabled {
  // from end of talking to recognition coming in
  switchable double expectedDelay = 3.0;
  
  transient long talkingSince;
  transient LongRange lastTalked;
  
  start {
    dm_registerAs_direct audioFeedbackPreventer();
    dm_vmBus_onMessage talking(r { talkingSince = sysNow() });
    dm_vmBus_onMessage doneTalking(r {
      lastTalked = longRange(talkingSince, sysNow());
      talkingSince = 0;
    });
  }
  
  // API
  
  bool recognizedSpeechIsProbablyMyOwnUtterance(O... _) {
    if (isTrue(dm_haveHeadphones())) {
      // Voice output goes to headphones, so we can't hear it
      print("Assuming I can't hear myself (headphones)");
      false;
    }
    if (talkingSince != 0) true;
    if (lastTalked == null) false;
    double elapsed = elapsedSeconds_sysNow(lastTalked.end);
    bool b = elapsed <= expectedDelay;
    if (nempty(_)) print(asList(_));
    print("Time since my last utterance: " + formatDouble(elapsed, 1) + "s, guessing it is " + (b ? "" : "not ") + " my utterance");
    ret b;
  }
}

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: #1027542
Snippet name: Audio Feedback Preventer [OK, stops speech output -> recognition endless loops]
Eternal ID of this version: #1027542/12
Text MD5: b8abb3b982e9e7a4ab6fab74115f22c0
Transpilation MD5: 18ac157b189f323ee165af3523104c91
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-03-23 14:13:30
Source code size: 1170 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 218 / 9503
Version history: 11 change(s)
Referenced in: [show references]