mirror of
https://github.com/R0m1k3/LiveFlow.git
synced 2026-10-16 11:50:07 +02:00
feat: diarisation des locuteurs en temps réel (ECAPA-TDNN + clustering incrémental)
- Nouveau module diarizer.py : EmbeddingModel (SpeechBrain ECAPA-TDNN) + SpeakerDiarizer par session - Backend : chargement modèle au lifespan, migration DB (colonne speaker), worker enrichi, exports avec locuteur - Frontend : badges locuteurs colorés (8 couleurs), toggle activation, copie avec [Locuteur X] - Config : DIARIZATION=on/off, DIARIZATION_THRESHOLD=0.70, PyTorch CPU-only dans Dockerfile - Rétrocompatible : désactivé par défaut (DIARIZATION=off)
This commit is contained in:
1 parent
ca936255e8
commit
284011428a
10 files changed
+325
-20
No files matched your search
+33
-5
@@ -15,6 +15,19 @@ const state = {
|
||||
|
||||
const BATCH_SAMPLES = 4096; // ~256 ms de PCM 16 kHz par message WebSocket
|
||||
|
||||
// --- Diarisation : palette de couleurs par locuteur ---
|
||||
const SPEAKER_COLORS = 8; // nombre de classes CSS .speaker-0 à .speaker-7
|
||||
const speakerMap = {}; // "Speaker 1" → 0, "Speaker 2" → 1, ...
|
||||
let speakerCounter = 0;
|
||||
|
||||
function getSpeakerColorIndex(speaker) {
|
||||
if (!(speaker in speakerMap)) {
|
||||
speakerMap[speaker] = speakerCounter % SPEAKER_COLORS;
|
||||
speakerCounter++;
|
||||
}
|
||||
return speakerMap[speaker];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- enregistrement
|
||||
|
||||
async function startRecording() {
|
||||
@@ -35,7 +48,11 @@ async function startRecording() {
|
||||
|
||||
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
state.ws = new WebSocket(`${proto}://${location.host}/ws`);
|
||||
state.ws.onopen = () => state.ws.send(JSON.stringify({ type: 'start', title: $('title').value }));
|
||||
state.ws.onopen = () => state.ws.send(JSON.stringify({
|
||||
type: 'start',
|
||||
title: $('title').value,
|
||||
diarization: $('diarization-cb').checked,
|
||||
}));
|
||||
state.ws.onmessage = onServerMessage;
|
||||
state.ws.onclose = () => { if (state.recording) stopRecording(true); };
|
||||
|
||||
@@ -136,12 +153,20 @@ function fmtTs(seconds) {
|
||||
|
||||
function clearTranscript() {
|
||||
$('transcript').innerHTML = '';
|
||||
// Reset le mapping locuteurs pour chaque nouvelle session
|
||||
for (const key in speakerMap) delete speakerMap[key];
|
||||
speakerCounter = 0;
|
||||
}
|
||||
|
||||
function appendSegment(seg) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'segment';
|
||||
div.innerHTML = `<span class="ts">${fmtTs(seg.t0)}</span><span class="text"></span>`;
|
||||
let speakerHtml = '';
|
||||
if (seg.speaker) {
|
||||
const ci = getSpeakerColorIndex(seg.speaker);
|
||||
speakerHtml = `<span class="speaker speaker-${ci}">${seg.speaker}</span>`;
|
||||
}
|
||||
div.innerHTML = `<span class="ts">${fmtTs(seg.t0)}</span>${speakerHtml}<span class="text"></span>`;
|
||||
div.querySelector('.text').textContent = seg.text;
|
||||
$('transcript').appendChild(div);
|
||||
$('transcript').scrollTop = $('transcript').scrollHeight;
|
||||
@@ -199,9 +224,12 @@ async function deleteCurrentMeeting() {
|
||||
}
|
||||
|
||||
async function copyTranscript() {
|
||||
const text = [...document.querySelectorAll('#transcript .segment .text')]
|
||||
.map((el) => el.textContent).join('\n');
|
||||
await navigator.clipboard.writeText(text);
|
||||
const lines = [...document.querySelectorAll('#transcript .segment')].map((el) => {
|
||||
const speaker = el.querySelector('.speaker');
|
||||
const text = el.querySelector('.text').textContent;
|
||||
return speaker ? `[${speaker.textContent}] ${text}` : text;
|
||||
});
|
||||
await navigator.clipboard.writeText(lines.join('\n'));
|
||||
$('copy-btn').textContent = '✓ Copié';
|
||||
setTimeout(() => ($('copy-btn').textContent = '📋 Copier'), 1500);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user