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

91
LINES

< > BotCompany Repo | #1016614 // Voice Output + AI Answer Mode [Dyn Module]

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

Uses 26535K of libraries. Click here for Pure Java version (12753L/72K).

!7

cmodule VoiceOutput > DynTextArea {
  S voice;
  float volume = 1f;
  transient JComboBox cbAnswerMode;
  switchable bool printStackTraces;
  bool showAnswerMode, mute;
  switchable bool useInternalAudioModule;
  switchable bool convertMP3ToWAV; // workaround
  
  start {
    if (empty(voice)) setField(voice := first(cereprocVoices()));
    set cereproc_printPageLoads;
    dm_registerAs voiceOutputModule();
  }
  
  visualize {
    //bindComboBoxToLiveValue_debug.set(true);
    JComponent ta = super.visualize();
    enableWordWrapForTextArea(textArea);
    //jPreemptEnterKey(textArea, rThread sayIt);
    onCtrlEnter(textArea, rThread sayIt);
    ret centerAndSouthWithMargins(ta,
      jvstackWithSpacing(
        centerAndEastWithMargin(
          centerAndEastWithMargin(withLabel("Voice:", jLiveValueComboBox(cereprocPlusLocalVoices(), dm_fieldLiveValue('voice))),
            jbutton("Say", rThread sayIt)),
            dm_checkBox('mute)),
        withLabel("Volume (all voices but flite/voice-rss):", jLiveValueSlider_bothWays(dm_fieldLiveValue('volume))),
        showAnswerMode ? jrightAlignedLine(jlabel("AI should answer (not really used yet):"), jComboBoxOnTrimmedFileContents(ll("Always", "Sometimes", "Never"), ai_answerModeFile(), ai_answerModeDefault())) : null));
  }
  
  // API
  
  void say(S s) enter {
    { lock lock; setText(s); }
    if (printStackTraces) printStackTrace();
    sayIt();
  }
  
  void sayIt enter {
    S s = trim(getText());
    if (empty(s)) ret;
    if (mute)
      ret with infoBox(s);
    if (empty(voice)) ret;
    for (fS line : tlft(s)) {
      flatInfoBox_topRightCorner(line);
      if (isCereprocVoice(voice))
        cereproc_silent(voice, line); // preload, then send message on bus
      S voiceRSS = dropPrefixOrNull("voice-rss/", voice);
      if (voiceRSS != null)
        voiceRSS_silent(voiceRSS, line);
      vmBus_send('talking, line, voice);
      afterwards { vmBus_send('doneTalking, line, voice); }
      new Matches m;
      if (isCereprocVoice(voice))
        cereproc(voice, line, gain := volume, playMP3 := convertMP3ToWAV ? (IVF1<File>) lambda1 playMP3ThroughWAV : null);
      else if (voiceRSS != null)
        playMP3(voiceRSS_silent(voiceRSS, line));
      else if (swic(voice, "flite/", m)) {
        if (useInternalAudioModule)
          dm_playWAV(flite_makeWAV(m.rest(), line));
        else
          flite_say(m.rest(), line);
      } else if (eq(voice, 'Kevin)) {
        kevin_volume = 1-(1-volume)/3;
        kevin(line);
        kevin_wait();
      } else
        print("Missing voice: " + voice);
    }
  }
  
  void clear() { setText(""); }
  
  void setVoice(S voice) {
    setField(+voice);
  }
  
  void preload(S s) {
    temp enter();
    if (isCereprocVoice(voice))
      cereproc_preload(voice, s);
  }
  
  // zero to one
  void setVolume(float volume) { setField(+volume); }
  float getVolume() { ret volume; }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016614
Snippet name: Voice Output + AI Answer Mode [Dyn Module]
Eternal ID of this version: #1016614/63
Text MD5: 8768db7714ea3cea778ac2e9afff4ee2
Transpilation MD5: 0c751ba5f741dcabcfb5bf817a0f9067
Author: stefan
Category: javax / dynamic modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-19 22:15:04
Source code size: 3005 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 479 / 96856
Version history: 62 change(s)
Referenced in: [show references]