diff --git a/src/ofTeleprompter.cpp b/src/ofTeleprompter.cpp index df1d0b8..6045282 100644 --- a/src/ofTeleprompter.cpp +++ b/src/ofTeleprompter.cpp @@ -21,9 +21,13 @@ void ofTeleprompter::setup() { } void ofTeleprompter::update() { - // set labels - currentSpeaker = script[currentLine].speaker; - currentEmotion = script[currentLine].emotion; + + if(ofGetFrameNum() < 2) { + currentSpeaker = script[currentLine].speaker; + currentEmotion = script[currentLine].emotion; + currentSentence = script[currentLine].sentence; + } + currentLineIndex = ofToString(currentLine + 1) + " / " + ofToString(script.size() + 1); // Teleprompter logic (letter by letter) @@ -44,7 +48,23 @@ void ofTeleprompter::update() { } else { ofJson json = ofJson::parse(llmResponse); std::string responseText = json.value("response", ""); - currentSentence = responseText; + size_t start = responseText.find('('); + size_t end = responseText.find(')'); + std::string speaker, sentence; + + if (start != std::string::npos && end != std::string::npos && end > start) { + speaker = responseText.substr(start + 1, end - start - 1); + size_t colon = responseText.find(':', end); + if (colon != std::string::npos) { + sentence = responseText.substr(colon + 1); + sentence.erase(0, sentence.find_first_not_of(" \t")); + } + } + + ofLog() << speaker; + currentSentence = sentence; + currentSpeaker = speaker; + currentEmotion = currentEmotionDetetced; displayedSentence.clear(); currentLetterIndex = 0; lastWordTime = ofGetElapsedTimeMillis(); @@ -92,9 +112,9 @@ void ofTeleprompter::loadText() { Line l; int randomIdx = ofRandom(7); l.idx = idx++; - l.speaker = entry.value("speaker", ""); - l.sentence = entry.value("content", ""); - l.emotion = emotions[(int)randomIdx]; + l.speaker = entry.value("first_speaker", ""); + l.sentence = entry.value("first_text", ""); + l.emotion = entry.value("first_emotion", ""); script.push_back(l); } } else { @@ -118,8 +138,8 @@ void ofTeleprompter::drawText() { ofSetColor(ofColor::white); // --- Display speaker and emotion centered at the top --- - std::string speakerText = "Speaker: " + script[currentLine].speaker; - std::string emotionText = "Emotion: " + script[currentLine].emotion; + std::string speakerText = "Speaker: " + currentSpeaker.getParameter().toString(); + std::string emotionText = "Emotion: " + currentEmotion.getParameter().toString(); ofRectangle speakerBox = detailsFont.getStringBoundingBox(speakerText, 0, 0); float speakerX = (ofGetWidth() - speakerBox.width) / 2.0f; @@ -211,10 +231,12 @@ void ofTeleprompter::nextLinePressed() { std::string emotion = script[currentLine].emotion; - llmThread.requestPrompt(speaker, sentence, emotion, temperature); + llmThread.requestPrompt(speaker, sentence, currentEmotionDetetced, temperature); waitingForLLM = true; // Don't set currentSentence yet! } else { + currentSpeaker = script[currentLine].speaker; + currentEmotion = script[currentLine].emotion; currentSentence = script[currentLine].sentence; displayedSentence.clear(); currentLetterIndex = 0; @@ -228,7 +250,10 @@ void ofTeleprompter::resetScript() { currentLine = 0; // Prepare teleprompter effect for letter-by-letter + currentSpeaker = script[currentLine].speaker; + currentEmotion = script[currentLine].emotion; currentSentence = script[currentLine].sentence; + displayedSentence.clear(); currentLetterIndex = 0; lastWordTime = ofGetElapsedTimeMillis(); diff --git a/src/ofTeleprompter.h b/src/ofTeleprompter.h index 4cc4480..8549dcd 100644 --- a/src/ofTeleprompter.h +++ b/src/ofTeleprompter.h @@ -47,7 +47,7 @@ class ofTeleprompter: public ofBaseApp{ /* script */ std::vector script; - std::string filePath = "text/Macbeth.json"; + std::string filePath = "text/preprocess_original.json"; int currentLine = 0; std::string currentLineString = "N/A"; const char* emotions[7] = {"anger", "disgust", "fear", "happiness", "neutral", "sadness", "surprise"};