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 26449K of libraries. Click here for Pure Java version (12753L/72K).


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/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();
  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
      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(, 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 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, unoaxrwscvea, 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: 325 / 92536
Version history: 62 change(s)
Referenced in: [show references]

Formerly at &