Warning: session_start(): open(/var/lib/php/sessions/sess_5qpil0qv3933jd752qviu0lurt, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
set flag NoAWT. set flag Android.
import android.app.*;
import android.content.*;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
import android.media.*;
static SpeechRecognizer sr;
static final String TAG = "MyStt3Activity";
static S language = "en-US";
static int extraResults = 1;
static bool fastSynthesis = false; // use device voice (faster)
static bool noSpeech = false; // disable speech output
static bool manualMode = false; // Start recognition on click only
sbool muteAlways, printErrors;
static volatile bool listening;
static new L history;
static Lock speechLock = lock();
svoid leoMain {
if (androidIsAdminMode()) {
androidUnsetAdminMode();
aShowStartScreen();
ret;
}
aHideTitleBar();
androidSay_keepEngine = true;
if (muteAlways) androidMuteAudio();
S hello = null;
/*if (args.length != 0 && args[0].equals("nogfx"))
setOpt(getMainClass(), "showPicture", false);*/
try {
history.add("*");
//hello = callStaticAnswerMethod("*", history);
if (hello == null) hello = german() ? "hallo" : "hello";
} catch (Throwable e) {
e.printStackTrace();
return;
}
//if (!noSpeech) say(hello);
callOptMC('happy);
androidUI(r {
//androidMuteAudio(androidActivity());
if (!manualMode)
newRecognizer();
});
thread "Long-Poll" {
repeat with sleep 1 {
// TODO: interrupt connection on cleanup
S action = postPageSilently("http://butter.botcompany.de:8080/1014866/raw", muricaCredentials());
if (nempty(action))
for (S s : lines(action)) say(s);
}
}
setLanguage(language);
aAddMenuItems("Switch to manual mode", "Switch to auto mode");
// init engine?
if (german()) androidSayInGerman(""); else androidSayInEnglish("");
noMainDone();
}
static void newRecognizer() {
sr = SpeechRecognizer.createSpeechRecognizer(androidActivity());
sr.setRecognitionListener(new listener());
recog();
}
static class listener implements RecognitionListener {
public void onReadyForSpeech(Bundle params) {
callOptMC('setBorderAndStatus, 0xFF66FF66,
german() ? "JETZT SPRECHEN!" : "TALK NOW!");
callOptMC('oh);
//showText(german() ? "SAG WAS." : "TALK NOW.");
}
public void onBeginningOfSpeech() {
//showText("User talks");
//callOptMC('oh);
if (!manualMode && !muteAlways)
androidMuteAudio(); // Mute now, so we don't hear the end-of-speech sound
}
public void onRmsChanged(float rmsdB) {}
public void onBufferReceived(byte[] buffer) {}
public void onEndOfSpeech() {
ping();
//showText("onEndOfSpeech");
callOptMC('setBorderAndStatus, aWhite(), baseStatus());
}
public void onError(int error) {
ping();
listening = false;
if (printErrors)
if (error == 6) // timeout
print("speech timeout");
else
print("error " + error); // screw the errors!
try {
sr.destroy();
} catch (Throwable e) {
print(e);
}
if (!manualMode)
newRecognizer();
else
callOptMC('setBorderAndStatus, aWhite(), baseStatus());
callOpt(getMainClass(), "happy");
}
public void onResults(Bundle results) {
ping();
listening = false;
//showText("onResults");
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
fS s = data.get(0);
mechQ(r {
appendToMechList_noUniq("Katze Speech Recognition Log With Date", "[" + localDateWithMilliseconds() + ", through phone] " + s) });
aSetText(userTextView, lang("You: ", "Du: ") + s);
showText((german() ? "Ich habe geh\u00f6rt: " : "I heard: ") + quote(s));
// TODO: fix the java strings umlaut problem
final boolean goodbye = match3("goodbye", s) || match3("bye", s) || match3("tsch\u00fcss", s) || match3("tsch\u00fcss ...", s);
thread {
// get answer
history.add(s);
handleCommand(s);
S answer;
try {
answer = goodbye ? "tsch\u00fcss" : callStaticAnswerMethod(s, history);
} catch (Throwable e) {
e.printStackTrace();
appendToFile(getProgramFile("errors.txt"), getTheStackTrace(e));
answer = "Fehler";
}
if (answer != null)
print(answer);
androidUI(r {
if (goodbye) {
print("\nGOODBYE!");
sr.destroy();
callOpt(getMainClass(), "disappear");
} else {
sr.stopListening();
listening = false;
//newRecognizer(); // always make a new one - gives endless errors
if (!manualMode)
recog();
}
});
} // end of thread
}
public void onPartialResults(Bundle partialResults) {
print("onPartialResults");
}
public void onEvent(int eventType, Bundle params) {
print("onEvent" + eventType);
}
}
static void recog() {
if (sr == null) ret with newRecognizer();
callOptMC('setBorderAndStatus, 0xFFFF0000,
german() ? "BITTE WARTEN" : "JUST A SEC"); // red (initializing speech recognizer)
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, extraResults);
// customize recognition time settings
callOpt(mc(), "recogTimeSettings", intent);
sr.startListening(intent);
listening = true;
//print("started listening");
}
static void say(fS s) {
ping();
lock speechLock;
showText(">> " + s);
aSetText(myTextView, lang("Me: ", "Ich: ") + s);
if (manualMode && listening) {
print("User is speaking, postponing speech output.");
ret;
}
androidUI_wait(f stopListening);
history.add(s);
mechQ(r {
appendToMechList_noUniq("Katze | Things the phone said", "[" + localDateWithMilliseconds() + "] " + s) });
if (!noSpeech) {
androidUnmuteAudio();
callOptMC('oh);
if (fastSynthesis) {
if (german()) androidSayInGerman(s); else androidSayInEnglish(s);
} else {
File mp3 = cereproc_silent(german() ? "Leopold" : "Jack", s);
androidPlayMp3(androidActivity(), mp3);
}
callOptMC('happy);
}
if (muteAlways)
androidMuteAudio();
}
static void stopListening() {
listening = false;
if (sr != null)
sr.stopListening();
}
svoid startListening() {
if (listening) ret;
listening = true;
recog();
}
sbool german() {
ret swic(language, "de");
}
svoid switchToManual {
stopListening();
manualMode = true;
androidUnmuteAudio();
}
svoid switchToAuto {
manualMode = false;
startListening();
androidUnmuteAudio();
}
svoid onMenuCommand(S s) {
//print("menu cmd: " + s);
handleCommand(s);
}
// spoken, typed or through menu
svoid handleCommand(S s) {
if "stop listening|Switch to manual mode" switchToManual();
if "Switch to auto mode" switchToAuto();
if "german|deutsch" setLanguage("de-DE");
if "english|englisch" setLanguage("en-US");
}
svoid cleanMeUp_leo {
if (sr != null) {
sr.destroy();
sr = null;
}
}
sS baseStatus() {
ret !manualMode ? "" :
german() ? "KLICKEN ZUM SPRECHEN" : "CLICK ME TO TALK";
}
sS lang(S en, S de) {
ret german() ? de : en;
}
svoid setLanguage(S l) {
language = l;
aSetText(lblInputView, inputViewLabel());
}