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

1  
!7
2  
3  
cmodule VoiceOutput > DynTextArea {
4  
  S voice;
5  
  float volume = 1f;
6  
  transient JComboBox cbAnswerMode;
7  
  switchable bool printStackTraces;
8  
  bool showAnswerMode, mute;
9  
  switchable bool useInternalAudioModule;
10  
  switchable bool convertMP3ToWAV; // workaround
11  
  
12  
  start {
13  
    if (empty(voice)) setField(voice := first(cereprocVoices()));
14  
    set cereproc_printPageLoads;
15  
    dm_registerAs voiceOutputModule();
16  
  }
17  
  
18  
  visualize {
19  
    //bindComboBoxToLiveValue_debug.set(true);
20  
    JComponent ta = super.visualize();
21  
    enableWordWrapForTextArea(textArea);
22  
    //jPreemptEnterKey(textArea, rThread sayIt);
23  
    onCtrlEnter(textArea, rThread sayIt);
24  
    ret centerAndSouthWithMargins(ta,
25  
      jvstackWithSpacing(
26  
        centerAndEastWithMargin(
27  
          centerAndEastWithMargin(withLabel("Voice:", jLiveValueComboBox(cereprocPlusLocalVoices(), dm_fieldLiveValue('voice))),
28  
            jbutton("Say", rThread sayIt)),
29  
            dm_checkBox('mute)),
30  
        withLabel("Volume (all voices but flite/voice-rss):", jLiveValueSlider_bothWays(dm_fieldLiveValue('volume))),
31  
        showAnswerMode ? jrightAlignedLine(jlabel("AI should answer (not really used yet):"), jComboBoxOnTrimmedFileContents(ll("Always", "Sometimes", "Never"), ai_answerModeFile(), ai_answerModeDefault())) : null));
32  
  }
33  
  
34  
  // API
35  
  
36  
  void say(S s) enter {
37  
    { lock lock; setText(s); }
38  
    if (printStackTraces) printStackTrace();
39  
    sayIt();
40  
  }
41  
  
42  
  void sayIt enter {
43  
    S s = trim(getText());
44  
    if (empty(s)) ret;
45  
    if (mute)
46  
      ret with infoBox(s);
47  
    if (empty(voice)) ret;
48  
    for (fS line : tlft(s)) {
49  
      flatInfoBox_topRightCorner(line);
50  
      if (isCereprocVoice(voice))
51  
        cereproc_silent(voice, line); // preload, then send message on bus
52  
      S voiceRSS = dropPrefixOrNull("voice-rss/", voice);
53  
      if (voiceRSS != null)
54  
        voiceRSS_silent(voiceRSS, line);
55  
      vmBus_send('talking, line, voice);
56  
      afterwards { vmBus_send('doneTalking, line, voice); }
57  
      new Matches m;
58  
      if (isCereprocVoice(voice))
59  
        cereproc(voice, line, gain := volume, playMP3 := convertMP3ToWAV ? (IVF1<File>) lambda1 playMP3ThroughWAV : null);
60  
      else if (voiceRSS != null)
61  
        playMP3(voiceRSS_silent(voiceRSS, line));
62  
      else if (swic(voice, "flite/", m)) {
63  
        if (useInternalAudioModule)
64  
          dm_playWAV(flite_makeWAV(m.rest(), line));
65  
        else
66  
          flite_say(m.rest(), line);
67  
      } else if (eq(voice, 'Kevin)) {
68  
        kevin_volume = 1-(1-volume)/3;
69  
        kevin(line);
70  
        kevin_wait();
71  
      } else
72  
        print("Missing voice: " + voice);
73  
    }
74  
  }
75  
  
76  
  void clear() { setText(""); }
77  
  
78  
  void setVoice(S voice) {
79  
    setField(+voice);
80  
  }
81  
  
82  
  void preload(S s) {
83  
    temp enter();
84  
    if (isCereprocVoice(voice))
85  
      cereproc_preload(voice, s);
86  
  }
87  
  
88  
  // zero to one
89  
  void setVolume(float volume) { setField(+volume); }
90  
  float getVolume() { ret volume; }
91  
}

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: 572 / 96988
Version history: 62 change(s)
Referenced in: [show references]