xxxxxxxxxx
153
// https://english.news.cn/20241028/c3e04a6dea494d798b9459a9393e67d2/c.html
// https://english.news.cn/20241028/89c26c682f1c423aa8603363a255e895/c.html
let speechRec;
let computer;
let triggerWords = [
"Innovation", "Advancement", "Leader", "Official", "Authoritative", "Command", "Influence", "Validate", "Endorsed", "Sovereign", "High quality", "Modern", "Digital China", "Leadership", "Pioneer", "Progress", "Socialism with Chinese characteristics", "Xi Jinping Thought", "Communist Party of China", "Unity", "Rejuvenation", "Belt and Road", "Cooperation", "Global", "Initiative", "Victory", "Triumph", "Accomplish", "Milestone", "Breakthrough", "Civilization", "Harmony", "Prosperity", "birth support", "demographic challenges", "maternity insurance", "childbirth reward", "paternity leave", "child care leave", "childbirth subsidy", "medical insurance reimbursement", "unintended pregnancies", "abortion care", "pediatric resources", "child care services", "housing provident fund", "population decline", "family planning policies", "phasing out", "launched", "program", "synthetic cells", "promote", "research", "innovation", "tackle", "pool expertise", "challenges", "mimic", "building", "constructing", "collaborations", "established", "alliance", "memorandum", "cooperation"
];
let mediaFiles = [
"Miniature Chatterbox 2024-10-10 02.32.40.mp4",
"Miniature Chatterbox 2024-10-10 02.32.42.mp4",
"Miniature Chatterbox 2024-10-10 02.32.54.mp4",
"Miniature Chatterbox 2024-10-10 02.33.36.mp4",
"Miniature Chatterbox 2024-10-10 02.33.37.mp4",
"Miniature Chatterbox 2024-10-10 02.33.42.mp4",
"Miniature Chatterbox 2024-10-10 02.45.15.mp4"
];
let videos = [];
let triggerCount = 0;
let activeVideos = [];
let totalSocialCredits = 0;
let lastAnnouncementTime = 0;
function preload() {
for (let file of mediaFiles) {
let vid = createVideo(file);
vid.elt.setAttribute('playsinline', '');
vid.elt.setAttribute('webkit-playsinline', '');
vid.hide();
videos.push(vid);
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(220);
console.log("Setting up speech recognition...");
speechRec = new p5.SpeechRec('en-US', gotSpeech);
speechRec.continuous = true;
speechRec.interimResults = false;
console.log("Setting up text-to-speech...");
computer = new p5.Speech();
textAlign(CENTER, CENTER);
textSize(32);
let button = createButton('Start/Stop Listening');
button.position(10, 10);
button.mousePressed(toggleListen);
console.log("Setup complete.");
}
function draw() {
background(255, 0, 0);
for (let i = activeVideos.length - 1; i >= 0; i--) {
let video = activeVideos[i];
image(video.element, video.x, video.y, video.width, video.height);
if (video.element.time() >= video.element.duration() - 0.1) {
activeVideos.splice(i, 1);
}
}
// Display trigger count and total social credits in yellow
fill(255, 255, 0); // Yellow color
textSize(32);
text("Social Credit Streak: " + triggerCount, width/2, 50);
text("Total Social Credits: " + totalSocialCredits, width/2, 100);
// Check if 30 seconds have passed since the last announcement
if (millis() - lastAnnouncementTime > 30000) {
announceTotal();
lastAnnouncementTime = millis();
}
}
function gotSpeech() {
console.log("Speech detected!");
if (speechRec.resultValue) {
let said = speechRec.resultString;
console.log("Transcription: " + said);
for (let word of triggerWords) {
if (said.toLowerCase().includes(word.toLowerCase())) {
triggerResponse(word);
break;
}
}
}
}
function triggerResponse(word) {
let creditsGained = Math.floor(Math.random() * (30 - 15 + 1)) + 15;
totalSocialCredits += creditsGained;
triggerCount++;
console.log(`You just gained ${creditsGained} social credits for using "${word}". Trigger count: ${triggerCount}`);
playRandomVideo();
computer.speak(`You just gained ${creditsGained} social credits for using ${word}. Social Credit Streak: ${triggerCount}`);
}
function announceTotal() {
computer.speak(`Total social credits gained in the last 30 seconds: ${totalSocialCredits}`);
totalSocialCredits = 0; // Reset the total after announcing
}
function playRandomVideo() {
let video = random(videos);
let x = random(width);
let y = random(height);
let w = random(100, width/2);
let h = w * (video.height / video.width);
video.show();
video.position(x, y);
video.size(w, h);
video.elt.oncanplay = () => {
let playPromise = video.elt.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
console.log('Video playback started');
activeVideos.push({element: video, x: x, y: y, width: w, height: h});
}).catch(error => {
console.error('Error playing video:', error);
video.hide(); // Hide the video if it fails to play
});
}
};
video.elt.onerror = () => {
console.error('Video error:', video.elt.error);
video.hide(); // Hide the video if there's an error
};
}
function toggleListen() {
if (speechRec.isListening) {
console.log("Stopping speech recognition...");
speechRec.stop();
} else {
console.log("Starting speech recognition...");
speechRec.start();
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}