!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) 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; } }