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

86
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 26420K of libraries. Click here for Pure Java version (12683L/71K).

!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):", 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
      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 (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   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1016614
Snippet name: Voice Output + AI Answer Mode [Dyn Module]
Eternal ID of this version: #1016614/61
Text MD5: cae659a18a105c3962ed5b9fe49a7a4c
Transpilation MD5: 84cee668488b6fc4314d2d6875e6445b
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-02-11 22:42:42
Source code size: 2785 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 297 / 80532
Version history: 60 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1016614 & http://1016614.tinybrain.de