-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
8,128 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link rel="icon" href="icon.png" type="image/png"> | ||
<title>Whatsyourtune</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.7.58/Tone.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/tensorflow/1.2.8/tf.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@magenta/music@^1.0.0/es6/core.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@magenta/music@^1.0.0/es6/music_vae.js"></script> | ||
<!-- clmtrackr library für emotion detection --> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/clmtrackr/1.1.2/clmtrackr.min.js"></script> | ||
|
||
</head> | ||
<body> | ||
<header> | ||
<img src="logo.png" alt="Whatsyourtune"> | ||
</header> | ||
<div class="content"> | ||
<video id="webcam" width="640" height="480" autoplay></video> | ||
<script src="index.js"></script> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Generieren einer Melodie basierend auf der erkannten Emotion | ||
async function generateMelody(emotion) { | ||
console.log(`Generating melody for: ${emotion}`); | ||
const characteristics = getMusicCharacteristics(emotion); | ||
|
||
try { | ||
// Magenta MusicVAE Model initialisieren | ||
const mvae = new music_vae.MusicVAE('https://storage.googleapis.com/magentadata/js/checkpoints/music_vae/trio_4bar'); | ||
await mvae.initialize(); | ||
console.log('Model loaded.'); | ||
|
||
// Sample-Melodie mit dem Model generieren | ||
const sample = await mvae.sample(1, characteristics.temperature); | ||
console.log('Melody generated.'); | ||
|
||
// Generierte Melodie abspielen | ||
const player = new core.Player(); | ||
player.start(sample[0]); | ||
console.log('Playback started.'); | ||
} catch (error) { | ||
console.error('Error generating melody:', error); | ||
} | ||
} | ||
|
||
// Je nach Emotion soll andere Musik abgespielt werden | ||
function getMusicCharacteristics(emotion) { | ||
switch(emotion) { | ||
case 'happy': | ||
return { temperature: 1.2 }; | ||
case 'sad': | ||
return { temperature: 0.8 }; | ||
default: | ||
return { temperature: 1.0 }; | ||
} | ||
} | ||
|
||
// Webcam starten und clmtrackr initialisieren | ||
function startWebcamAndTracking() { | ||
const video = document.getElementById('webcam'); | ||
|
||
// Webcam-Access | ||
navigator.mediaDevices.getUserMedia({ video: true }) | ||
.then((stream) => { | ||
video.srcObject = stream; | ||
video.onloadedmetadata = function() { | ||
video.play(); | ||
// Wenn der Webcamfeed ready ist, anfangen Gesichtszüge zu erkennen | ||
startTracking(video); | ||
}; | ||
}) | ||
.catch((err) => { | ||
console.error("Error accessing webcam:", err); | ||
}); | ||
} | ||
|
||
// Clmtrackr initialisieren und starten | ||
function startTracking(videoElement) { | ||
var ctracker = new clm.tracker(); | ||
ctracker.init(); | ||
ctracker.start(videoElement); | ||
|
||
// Durchgehend nach Emotionen checken | ||
trackExpression(ctracker); | ||
} | ||
|
||
// Emotion aus Gesichtszüge herausinterpretieren | ||
function trackExpression(ctracker) { | ||
function drawLoop() { | ||
requestAnimationFrame(drawLoop); | ||
var positions = ctracker.getCurrentPosition(); | ||
if (positions) { | ||
// Basic Logik um Emotionen zu erkennen, basierend auf der Distanz der Mundecken | ||
const mouthCornerDistance = Math.abs(positions[44][1] - positions[50][1]); // Beispiel indices für Mundecken | ||
const emotion = mouthCornerDistance > 15 ? 'happy' : 'sad'; | ||
|
||
// Melodie generieren | ||
generateMelody(emotion); | ||
} | ||
} | ||
drawLoop(); | ||
} | ||
// Webcam und Facial Tracking starten | ||
startWebcamAndTracking(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.