-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
121 lines (89 loc) · 2.5 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// created by sarah ciston
// with p5.js, ml5.js, p5.speech libraries
// and gpt2 deepAI api
let url;
let staticImage;
let originalText = 'IVO-TextOnly.txt';
let textGPT = 'IVO-GPT2generatedONLY.txt';
let Avenir = 'Avenir.otf';
let img = 'CMstaticFrame2.jpg';
let msgOrig = [];
let msgGPT = [];
let latestOrig;
let latestGPT;
let talk = new p5.Speech();
let talkRate;
let uNet;
let video;
let segmentationImage;
let canvas;
function preload() {
originalText = loadStrings(originalText);
textGPT = loadStrings(textGPT);
uNet = ml5.uNet('face');
Avenir = loadFont(Avenir);
img = loadImage(img);
}
function setup(){
canvas = createCanvas(1024, 768) //, WEBGL);
frameRate(0.5);
textSize(width/25);
textFont(Avenir);
video = createCapture(VIDEO);
video.size(width, height);
video.hide();
segmentationImage = createImage(width, height);
uNet.segment(video, makeCutout);
function makeCutout(error, cutout) {
if (error) {
console.error(error);
return;
}
segmentationImage = cutout.backgroundMask;
uNet.segment(video, makeCutout);
}
talk.setVoice(49); //'Google UK English'
url = new URL(document.location); //for ?frame param
}
function draw() {
background(0);
//draw random message from original samples, behind face
append(msgOrig, random(originalText));
latestOrig = (msgOrig.length - 1);
fill(50, 205, 50); //lime
text(msgOrig[latestOrig], random(800), random(800), 800, 800)
//draw face mask
image(segmentationImage, 0, 0, width, height);
//draw random message from GPT results, in front of face
append(msgGPT, random(textGPT));
latestGPT = (msgGPT.length - 1);
fill(0, 255, 255); //cyan //(161, 95, 251); //magenta
text(msgGPT[latestGPT], random(800), random(800), 800, 800)
//speak latest message from original samples & GPT
talk.speak(msgGPT[latestGPT]);
// if(frameCount % talkRate == 0){}; //change rate TBD
//create static frame with ?frame URL param
if (url.searchParams.has("frame") && frameCount > 1) {
noLoop();
image(img, 0, 0, windowWidth, windowHeight);
};
}
//after DOM loads//
//toggle fullscreen on mouse press
function mousePressed() {
let fs = fullscreen();
fullscreen(!fs);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function keyPressed() {
if (keyCode === ENTER) {
noLoop();
staticFrame();
}
}
//make screengrab on ENTER key or ?frame URL
function staticFrame() {
save('Ciston-staticFrame' + new Date() +'.jpg');
}