Browse Source

Dev week end

main
Cailean 3 weeks ago
parent
commit
5cff95f956
  1. 1868
      bin/data/text/preprocess_presentation.json
  2. 67
      src/ofApp.cpp
  3. 4
      src/ofApp.h
  4. 31
      src/ofTeleprompter.cpp

1868
bin/data/text/preprocess_presentation.json

File diff suppressed because it is too large

67
src/ofApp.cpp

@ -13,12 +13,15 @@ void ofApp::setup(){
videoFrame.allocate(1280, 720, OF_IMAGE_COLOR);
webcam.setDeviceID(0);
webcam.setDesiredFrameRate(60);
webcam.setDesiredFrameRate(30);
webcam.setup(webcamWidth, webcamHeight);
ofLog() << "Webcam size: " << webcam.getWidth() << "x" << webcam.getHeight();
onnx.setup(&inputImage); // setup onnx -> will need to pass in a pointer to the two fbos?
textFont.load("Avara-Bold.otf", 32);
infoFont.load("Avara-Bold.otf", 24);
}
//--------------------------------------------------------------
@ -48,6 +51,50 @@ void ofApp::update(){
//--------------------------------------------------------------
void ofApp::draw(){
onnx.draw();
ofPushStyle();
ofSetColor(ofColor::red);
// Get current info from teleprompter
std::string speakerText = "Speaker: " + teleprompter->currentSpeaker.getParameter().toString();
std::string emotionText = "Emotion: " + teleprompter->currentEmotion.getParameter().toString();
// Calculate positions for speaker and emotion text
ofRectangle speakerBox = infoFont.getStringBoundingBox(speakerText, 0, 0);
float speakerX = (ofGetWidth() - speakerBox.width) / 2.0f;
float speakerY = 128;
ofRectangle emotionBox = infoFont.getStringBoundingBox(emotionText, 0, 0);
float emotionX = (ofGetWidth() - emotionBox.width) / 2.0f;
float emotionY = speakerY + speakerBox.height + 10;
// Draw speaker and emotion
infoFont.drawString(speakerText, speakerX, speakerY);
infoFont.drawString(emotionText, emotionX, emotionY);
ofSetColor(ofColor::red);
float margin = 128;
float maxWidth = ofGetWidth() - margin * 2;
std::string wrapped = wrapStringToWidth(teleprompter->displayedSentence, maxWidth);
// Split and draw wrapped text
std::vector<std::string> lines;
std::istringstream iss(wrapped);
std::string line;
while (std::getline(iss, line)) {
lines.push_back(line);
}
float totalHeight = lines.size() * textFont.getLineHeight();
float startY = (ofGetHeight() / 2.0f) - (totalHeight / 2.0f);
for (size_t i = 0; i < lines.size(); ++i) {
ofRectangle bbox = textFont.getStringBoundingBox(lines[i], 0, 0);
float x = (ofGetWidth() - bbox.width) / 2.0f; // Calculate center position
float y = startY + i * textFont.getLineHeight();
textFont.drawString(lines[i], x, y);
}
ofPopStyle();
}
//--------------------------------------------------------------
@ -65,4 +112,22 @@ void ofApp::keyPressed(int key){
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
std::string ofApp::wrapStringToWidth(const std::string& text, float maxWidth) {
std::istringstream iss(text);
std::string word;
std::string wrapped, line;
while (iss >> word) {
std::string testLine = line.empty() ? word : line + " " + word;
ofRectangle bbox = textFont.getStringBoundingBox(testLine, 0, 0);
if (bbox.width > maxWidth && !line.empty()) {
wrapped += line + "\n";
line = word;
} else {
line = testLine;
}
}
if (!line.empty()) wrapped += line;
return wrapped;
}

4
src/ofApp.h

@ -28,4 +28,8 @@ class ofApp : public ofBaseApp{
ofVideoGrabber webcam;
int webcamWidth = 1280;
int webcamHeight = 720;
private:
ofTrueTypeFont textFont;
ofTrueTypeFont infoFont;
std::string wrapStringToWidth(const std::string& text, float maxWidth);
};

31
src/ofTeleprompter.cpp

@ -12,8 +12,8 @@ void ofTeleprompter::setup() {
activeScript = &script;
textFont.load("Roboto-SemiBold.ttf", 32);
detailsFont.load("Roboto-SemiBold.ttf", 30);
textFont.load("Roboto-SemiBold.ttf", 38);
detailsFont.load("Roboto-SemiBold.ttf", 34);
// Prepare first line for teleprompter
currentSentence = (*activeScript)[currentLine].sentence;
@ -48,14 +48,17 @@ void ofTeleprompter::update() {
// Waits for llm thread to send a response before displaying!
if (waitingForLLM && llmThread.isResultReady()) {
llmResponse = llmThread.getResult();
std::string speaker, sentence;
if (llmResponse.empty()) {
ofLogError() << "LLM response is empty!";
speaker = "STAGE DIRECTION";
sentence = "LLM response is empty";
} else {
ofJson json = ofJson::parse(llmResponse);
std::string responseText = json.value("response", "");
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);
@ -65,16 +68,16 @@ void ofTeleprompter::update() {
sentence.erase(0, sentence.find_first_not_of(" \t"));
}
}
ofLog() << speaker;
currentSentence = sentence;
currentSpeaker = speaker;
currentEmotion = currentEmotionDetetced;
displayedSentence.clear();
currentLetterIndex = 0;
lastWordTime = ofGetElapsedTimeMillis();
waitingForLLM = false;
}
ofLog() << speaker;
currentSentence = sentence;
currentSpeaker = speaker;
currentEmotion = currentEmotionDetetced;
displayedSentence.clear();
currentLetterIndex = 0;
lastWordTime = ofGetElapsedTimeMillis();
waitingForLLM = false;
}
}
@ -227,7 +230,9 @@ void ofTeleprompter::nextLinePressed() {
ofLog() << "Next Line!";
if (currentLine <= (*activeScript).size()) {
if (currentLine >= (*activeScript).size() - 1) {
currentLine = 0;
} else {
currentLine++;
}

Loading…
Cancel
Save