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


< > 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).


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 {
    JComponent ta = super.visualize();
    //jPreemptEnterKey(textArea, rThread sayIt);
    onCtrlEnter(textArea, rThread sayIt);
    ret centerAndSouthWithMargins(ta,
          centerAndEastWithMargin(withLabel("Voice:", jLiveValueComboBox(cereprocPlusLocalVoices(), dm_fieldLiveValue('voice))),
            jbutton("Say", rThread sayIt)),
        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();
  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)) {
      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(, line));
          flite_say(, line);
      } else if (eq(voice, 'Kevin)) {
        kevin_volume = 1-(1-volume)/3;
      } else
        print("Missing voice: " + voice);
  void clear() { setText(""); }
  void setVoice(S 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 &