Spaces:
Running on Zero
Running on Zero
Pause microphone capture during inference and allow one explicit next direction
Browse files- README.md +1 -1
- assets/collection.js +1 -1
- assets/desk.html +2 -0
- assets/studio.css +2 -0
- assets/studio.js +103 -28
README.md
CHANGED
|
@@ -33,7 +33,7 @@ A research prototype for directing a continuous generated shot with spoken or wr
|
|
| 33 |
|
| 34 |
Choose FastFrames-S (default, 1.3B) or FastFrames-L (14B) before starting a shot. Each session uses the same model for its opening, continuations and variants. When the session ends, the model selector becomes available again.
|
| 35 |
|
| 36 |
-
Select Voice and start the microphone, or select Text, write a direction and press Generate segment (Enter to send, Shift+Enter for a new line). Text mode releases the microphone. Switching inputs preserves the shot. Each accepted direction generates one silent segment at 832 × 480 and 16 fps. Choose 1–8 whole seconds (default 4) before submitting each direction. Each second contains 16 frames. The opening generates one extra latent and trims one leading decoded frame after the model’s three startup frames to deliver an exact whole-second clip. The last segment loops locally while you think or the next cue is being prepared. Toggle Loop on the monitor to freeze it. Reduced-motion preferences disable looping by default. Repeats never enter the exported recording. End session joins completed segments into a downloadable MP4. Speak in a quiet place. A continuous 3-second pause ends a spoken direction. Resuming sooner keeps the whole cue together. Directions can last up to 45 seconds. If that limit is exceeded, the mic pauses and asks for a shorter cue before submitting any audio from it. Muting stops capture immediately. A spoken direction in progress stays in memory in this tab until you resume it, send it or discard it. Time spent muted is excluded. A cue that has already been submitted keeps its place in the queue. Ending the session clears its voice draft. The monitor plays the generated frames on an inline canvas, including on iPhone. The studio publishes JPEG strips of eight frames as the generator produces them. Inline playback starts at the first available strip, before the checkpoint and final MP4 are ready.
|
| 37 |
|
| 38 |
After a clip is complete, voice and text directions can continue the shot or redo its last segment. Check **Redo last segment** to force a variant for one instruction. A redo uses the duration and the starting state of the original (the same initial seed for the opening). The next-segment duration selector is preserved. With an ambiguous cue, answer “last segment” or “next segment” by voice, text or button; the studio keeps the original direction while waiting. Review both versions, then choose **Keep original** or **Use variant**. Ending during review exports the original. Only chosen clips enter the recording and future continuity.
|
| 39 |
|
|
|
|
| 33 |
|
| 34 |
Choose FastFrames-S (default, 1.3B) or FastFrames-L (14B) before starting a shot. Each session uses the same model for its opening, continuations and variants. When the session ends, the model selector becomes available again.
|
| 35 |
|
| 36 |
+
Select Voice and start the microphone, or select Text, write a direction and press Generate segment (Enter to send, Shift+Enter for a new line). Text mode releases the microphone. Switching inputs preserves the shot. Each accepted direction generates one silent segment at 832 × 480 and 16 fps. Choose 1–8 whole seconds (default 4) before submitting each direction. Each second contains 16 frames. The opening generates one extra latent and trims one leading decoded frame after the model’s three startup frames to deliver an exact whole-second clip. The last segment loops locally while you think or the next cue is being prepared. Toggle Loop on the monitor to freeze it. Reduced-motion preferences disable looping by default. Repeats never enter the exported recording. End session joins completed segments into a downloadable MP4. Speak in a quiet place. A continuous 3-second pause ends a spoken direction. Resuming sooner keeps the whole cue together. Directions can last up to 45 seconds. If that limit is exceeded, the mic pauses and asks for a shorter cue before submitting any audio from it. Muting stops capture immediately. A spoken direction in progress stays in memory in this tab until you resume it, send it or discard it. Time spent muted is excluded. A cue that has already been submitted keeps its place in the queue. Ending the session clears its voice draft. The monitor plays the generated frames on an inline canvas, including on iPhone. The studio publishes JPEG strips of eight frames as the generator produces them. Inline playback starts at the first available strip, before the checkpoint and final MP4 are ready. Submitting a direction releases the microphone during transcription, interpretation and rendering. If you left listening on, it resumes when the segment is published. Choose Keep muted or Text to cancel automatic listening. Dictate next direction lets you record one upcoming cue during processing; it waits for the current segment before dispatch. A manually muted mic stays muted after that one cue. In Text mode you can queue the next written direction while the preview plays. Generation of the next segment starts after the current segment and its continuity window have committed and the first playback has finished. API clients can request the same preview events with stream_preview set to true on live_take. The complete take uses a native MP4 player with inline playback and download.
|
| 37 |
|
| 38 |
After a clip is complete, voice and text directions can continue the shot or redo its last segment. Check **Redo last segment** to force a variant for one instruction. A redo uses the duration and the starting state of the original (the same initial seed for the opening). The next-segment duration selector is preserved. With an ambiguous cue, answer “last segment” or “next segment” by voice, text or button; the studio keeps the original direction while waiting. Review both versions, then choose **Keep original** or **Use variant**. Ending during review exports the original. Only chosen clips enter the recording and future continuity.
|
| 39 |
|
assets/collection.js
CHANGED
|
@@ -58,7 +58,7 @@ function sessionCollection(){
|
|
| 58 |
timeline?.close();
|
| 59 |
view=next;
|
| 60 |
if(next==="gallery"){
|
| 61 |
-
|
| 62 |
call("list");
|
| 63 |
}else{
|
| 64 |
pending=null;selected="";
|
|
|
|
| 58 |
timeline?.close();
|
| 59 |
view=next;
|
| 60 |
if(next==="gallery"){
|
| 61 |
+
pauseMic();
|
| 62 |
call("list");
|
| 63 |
}else{
|
| 64 |
pending=null;selected="";
|
assets/desk.html
CHANGED
|
@@ -12,6 +12,8 @@
|
|
| 12 |
</button>
|
| 13 |
<canvas id="mic-level" width="88" height="32" aria-hidden="true"></canvas>
|
| 14 |
<small id="voice-hint" data-tr="quietHint">Speak in a quiet place. Pause for 3 seconds to send.</small>
|
|
|
|
|
|
|
| 15 |
<div id="voice-draft-actions" role="group" aria-label="Paused direction" data-aria-en="Paused direction" data-aria-fr="Consigne en pause" hidden>
|
| 16 |
<button type="button" id="send-voice" data-tr="sendVoice">Send</button>
|
| 17 |
<button type="button" id="discard-voice" data-tr="discardVoice">Discard</button>
|
|
|
|
| 12 |
</button>
|
| 13 |
<canvas id="mic-level" width="88" height="32" aria-hidden="true"></canvas>
|
| 14 |
<small id="voice-hint" data-tr="quietHint">Speak in a quiet place. Pause for 3 seconds to send.</small>
|
| 15 |
+
<small id="voice-queued" role="status" data-tr="queuedVoice" hidden>Next direction queued.</small>
|
| 16 |
+
<button type="button" id="dictate-next" data-tr="dictateNext" hidden>Dictate next direction</button>
|
| 17 |
<div id="voice-draft-actions" role="group" aria-label="Paused direction" data-aria-en="Paused direction" data-aria-fr="Consigne en pause" hidden>
|
| 18 |
<button type="button" id="send-voice" data-tr="sendVoice">Send</button>
|
| 19 |
<button type="button" id="discard-voice" data-tr="discardVoice">Discard</button>
|
assets/studio.css
CHANGED
|
@@ -30,6 +30,8 @@
|
|
| 30 |
.console-body{display:grid;grid-template-columns:minmax(155px,.85fr) minmax(0,1fr) minmax(0,1.1fr);align-items:stretch;padding:13px 0}
|
| 31 |
#voice-control{display:grid;grid-template-columns:auto minmax(0,1fr);align-content:center;justify-items:start;gap:6px 8px}
|
| 32 |
#voice-hint{grid-column:1/-1;color:#c0c8c2;font:400 13px/1.35 Barlow,Arial,sans-serif}
|
|
|
|
|
|
|
| 33 |
#voice-draft-actions{grid-column:1/-1;display:flex;align-items:center;flex-wrap:wrap;gap:4px}
|
| 34 |
#studio #voice-draft-actions button{min-height:44px;padding:0 10px;border:1px solid transparent;border-radius:5px;background:transparent;color:#ced5d0;font:600 14px/1.2 Barlow,Arial,sans-serif}
|
| 35 |
#studio #voice-draft-actions #send-voice{background:#303a34;border-color:#68776d;color:#f2f3ee}
|
|
|
|
| 30 |
.console-body{display:grid;grid-template-columns:minmax(155px,.85fr) minmax(0,1fr) minmax(0,1.1fr);align-items:stretch;padding:13px 0}
|
| 31 |
#voice-control{display:grid;grid-template-columns:auto minmax(0,1fr);align-content:center;justify-items:start;gap:6px 8px}
|
| 32 |
#voice-hint{grid-column:1/-1;color:#c0c8c2;font:400 13px/1.35 Barlow,Arial,sans-serif}
|
| 33 |
+
#studio #dictate-next{grid-column:1/-1;min-height:44px;padding:0 10px;border:1px solid #68776d;border-radius:5px;background:#303a34;color:#f2f3ee;font:600 14px/1.2 Barlow,Arial,sans-serif}
|
| 34 |
+
#voice-queued{grid-column:1/-1;color:#d1d7d3;font:600 13px/1.35 Barlow,Arial,sans-serif}
|
| 35 |
#voice-draft-actions{grid-column:1/-1;display:flex;align-items:center;flex-wrap:wrap;gap:4px}
|
| 36 |
#studio #voice-draft-actions button{min-height:44px;padding:0 10px;border:1px solid transparent;border-radius:5px;background:transparent;color:#ced5d0;font:600 14px/1.2 Barlow,Arial,sans-serif}
|
| 37 |
#studio #voice-draft-actions #send-voice{background:#303a34;border-color:#68776d;color:#f2f3ee}
|
assets/studio.js
CHANGED
|
@@ -50,6 +50,11 @@ const copy = {
|
|
| 50 |
quietHint:["Speak in a quiet place. Pause for 3 seconds to send.","Parle dans un endroit calme. Une pause de 3 s envoie la consigne."],
|
| 51 |
pausedHint:["Mic off. Your direction is paused.","Micro coupé. Ta consigne est en pause."],
|
| 52 |
continueHint:["Continue your direction, then pause for 3 seconds to send.","Continue ta consigne, puis laisse 3 s de silence pour l’envoyer."],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
resumeVoice:["Resume","Reprendre"],sendVoice:["Send","Envoyer"],discardVoice:["Discard","Effacer"],
|
| 54 |
phraseTooLong:["Direction too long. Unmute and try a shorter cue (up to 45 seconds).","Consigne trop longue. Réactive le micro et réessaie en 45 secondes maximum."],
|
| 55 |
framesReady:["frames available","images disponibles"],
|
|
@@ -89,6 +94,9 @@ const tr = k => (copy[k] || [k,k])[lang==="fr"?1:0];
|
|
| 89 |
let inputMode = "voice", lastSource = "", interpreter = "", submittedDraft = null;
|
| 90 |
let take = null, status = "idle", mode = "idle", focus="", prompt="", lastHeard="";
|
| 91 |
let stream=null, ctx=null, node=null, opening=false, stopped=false, micEpoch=0, micIssue="";
|
|
|
|
|
|
|
|
|
|
| 92 |
let ready=false, busy=false, saved=false, seq=0, applied=0, visionRev=0, retryKind="", pendingStill="", lastSegment=null;
|
| 93 |
let approvedClip=null, variantClip=null, questionId=null, inFlight=null, choosing=false, editOperation="append";
|
| 94 |
let queue=[], pre=[], blocks=[], voice=false, quiet=0, loud=0, baseline=.003, watchdog=0;
|
|
@@ -108,7 +116,10 @@ by("loop-preview").addEventListener("click",()=>{
|
|
| 108 |
try{localStorage.setItem("ffv-loop",loopEnabled?"on":"off");}catch{}
|
| 109 |
syncLoop();label();
|
| 110 |
});
|
| 111 |
-
document.addEventListener?.("visibilitychange",
|
|
|
|
|
|
|
|
|
|
| 112 |
syncLoop();
|
| 113 |
const workingStages=new Set(["permission","starting","sent","transcribing","interpreting","renderPending","queued","allocated","restoring","generating","redoGenerating","saving","encoding","loading","deciding","stopping","finalizing","archiving"]);
|
| 114 |
const errorStages=new Set(["mic_error","phraseTooLong","empty","speech_error","quota","gpu_error","hardware","connection","disk_full","expired","play_error","export_error","archive_error","decision_error","invalid_model","invalid_target","invalid_operation","invalid_seconds","invalid_text","locked_segment","history_error"]);
|
|
@@ -138,15 +149,27 @@ function label(){
|
|
| 138 |
root.querySelectorAll("[data-aria-fr]").forEach(e=>e.setAttribute("aria-label",lang==="fr"?e.dataset.ariaFr:e.dataset.ariaEn));
|
| 139 |
root.querySelectorAll("[data-tr]").forEach(e=>e.textContent=tr(e.dataset.tr));
|
| 140 |
langButtons.forEach((b,i)=>b.setAttribute("aria-pressed",String(i===(lang==="fr"?1:0))));
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
by("mode-voice").setAttribute("aria-pressed",String(inputMode==="voice"));
|
| 143 |
by("mode-text").setAttribute("aria-pressed",String(inputMode==="text"));
|
| 144 |
by("voice-control").hidden=inputMode!=="voice";
|
| 145 |
const paused=voiceDraft.length>0 && !stream && !stopped;
|
| 146 |
by("voice-draft-actions").hidden=!paused;
|
| 147 |
-
by("send-voice").disabled=opening||stopped||Boolean(variantClip)||(busy && (editOperation==="redo_last"||Boolean(questionId)));
|
| 148 |
by("discard-voice").disabled=opening;
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
by("text-control").hidden=inputMode!=="text";
|
| 151 |
deskEl.dataset.input=inputMode;
|
| 152 |
deskEl.dataset.active=String(Boolean(take));
|
|
@@ -178,7 +201,7 @@ function label(){
|
|
| 178 |
const muted = Boolean(inputMode==="voice" && take && !stream && !opening && !stopped);
|
| 179 |
mic.dataset.micState = muted ? "muted" : stream ? "listening" : "idle";
|
| 180 |
retry.hidden=!retryKind;
|
| 181 |
-
mic.disabled=
|
| 182 |
end.disabled=(!take&&!opening)||stopped;
|
| 183 |
end.title=tr("endSave");
|
| 184 |
end.setAttribute("aria-label",tr("endSave"));
|
|
@@ -193,23 +216,50 @@ function emit(name,data){ props.value=JSON.stringify({...data,media_key:media.ke
|
|
| 193 |
function setMode(m){mode=m;monitor.dataset.mode=m;}
|
| 194 |
function clearPhrase(){pre=[];blocks=[];voice=false;quiet=0;loud=0;phraseSeconds=0;baseline=.003;}
|
| 195 |
function draw(level=0){meter.clearRect(0,0,88,32);for(let i=0;i<12;i++){meter.fillStyle=level>i/12?"#ffb354":"#515854";const h=5+i*1.8;meter.fillRect(i*7,16-h/2,4,h);}}
|
| 196 |
-
function release(){
|
| 197 |
micEpoch++;opening=false;
|
|
|
|
| 198 |
if(node){if(node.port)node.port.onmessage=null;else node.onaudioprocess=null;node.disconnect();node=null;}
|
|
|
|
| 199 |
if(stream){stream.getTracks().forEach(t=>t.stop());stream=null;}
|
| 200 |
-
if(ctx){
|
|
|
|
| 201 |
clearPhrase();draw();label();
|
| 202 |
}
|
| 203 |
function pauseMic(){
|
|
|
|
| 204 |
retainSpeech();
|
| 205 |
release();
|
| 206 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
function resetEditing(){
|
|
|
|
| 208 |
livePreview=null;
|
| 209 |
voiceDraft=new Int16Array(0);
|
| 210 |
approvedClip=variantClip=questionId=inFlight=null;choosing=false;editOperation="append";forceRedo.checked=false;
|
| 211 |
}
|
| 212 |
function finish(k){
|
|
|
|
| 213 |
resetEditing();
|
| 214 |
clearTimeout(watchdog); submittedDraft=null;release();queue=[];take=null;ready=false;busy=false;retryKind="";stopped=false;playback.clear();
|
| 215 |
if(k==="finished")saved=true;
|
|
@@ -239,9 +289,10 @@ function cueOptions(){
|
|
| 239 |
}
|
| 240 |
forceRedo.addEventListener("change",label);
|
| 241 |
function pump(){if(!take||!ready||busy||stopped||variantClip||!queue.length)return;timeline?.close();busy=true;retryKind="";
|
| 242 |
-
const cue=queue.shift(), written=cue.text!==undefined;
|
|
|
|
| 243 |
inFlight=cue;setStatus("sent");
|
| 244 |
-
emit(written?"written":"phrase",{take,seq:++seq,...cue});
|
| 245 |
}
|
| 246 |
function retainSpeech(){
|
| 247 |
if(!voice || !blocks.length || !ctx || loud<=.16)return false;
|
|
@@ -255,9 +306,10 @@ function retainSpeech(){
|
|
| 255 |
return true;
|
| 256 |
}
|
| 257 |
function submitVoice(){
|
| 258 |
-
if(!voiceDraft.length || !take || stopped || variantClip)return;
|
| 259 |
-
queue.push({
|
| 260 |
voiceDraft=new Int16Array(0);
|
|
|
|
| 261 |
label();pump();
|
| 262 |
}
|
| 263 |
function flush(){
|
|
@@ -266,7 +318,7 @@ function flush(){
|
|
| 266 |
if(fresh)submitVoice();
|
| 267 |
}
|
| 268 |
function sample(a){
|
| 269 |
-
if(!ctx||!take||stopped||variantClip||(
|
| 270 |
const dt=a.length/ctx.sampleRate;let sum=0;for(const x of a)sum+=x*x;
|
| 271 |
const rms=Math.sqrt(sum/a.length);draw(Math.min(1,rms*9));
|
| 272 |
const sound=rms>Math.max(.008,baseline*3.2);
|
|
@@ -288,7 +340,7 @@ function startTake(){
|
|
| 288 |
}
|
| 289 |
function chooseInput(next){
|
| 290 |
inputMode=next;
|
| 291 |
-
if(next==="text"
|
| 292 |
label();
|
| 293 |
if(next==="text")draft.focus();
|
| 294 |
}
|
|
@@ -309,19 +361,27 @@ draft.addEventListener("keydown",e=>{
|
|
| 309 |
if(e.key==="Enter"&&!e.shiftKey&&!e.isComposing){e.preventDefault();sendWritten();}
|
| 310 |
});
|
| 311 |
async function openMic(){
|
| 312 |
-
if(opening)return;
|
| 313 |
micIssue="";opening=true;const epoch=++micEpoch;
|
| 314 |
label();
|
| 315 |
try{
|
| 316 |
const capture=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:true,noiseSuppression:true},video:false});
|
| 317 |
if(epoch!==micEpoch){capture.getTracks().forEach(t=>t.stop());return;}
|
| 318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
if(epoch!==micEpoch)return;
|
| 320 |
const moduleSource = /* WORKLET_MODULE */ "";
|
| 321 |
-
|
| 322 |
-
let timer;
|
| 323 |
try{
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
if(epoch!==micEpoch)return;
|
| 326 |
node=new AudioWorkletNode(activeContext,"ffv-capture");
|
| 327 |
node.port.onmessage=e=>{if(epoch===micEpoch)sample(e.data);};
|
|
@@ -329,9 +389,9 @@ async function openMic(){
|
|
| 329 |
if(epoch!==micEpoch)return;
|
| 330 |
node=activeContext.createScriptProcessor(1024,1,1);
|
| 331 |
node.onaudioprocess=e=>{if(epoch===micEpoch)sample(new Float32Array(e.inputBuffer.getChannelData(0)));};
|
| 332 |
-
}finally{clearTimeout(timer);URL.revokeObjectURL(moduleURL);}
|
| 333 |
-
|
| 334 |
-
|
| 335 |
capture.getAudioTracks()[0].addEventListener("ended",()=>{if(capture===stream)micFailed();});
|
| 336 |
if(!take)startTake();
|
| 337 |
if (status==="mic_error" || status==="phraseTooLong") setStatus(applied?"holding":"armed");
|
|
@@ -339,17 +399,29 @@ async function openMic(){
|
|
| 339 |
finally{if(epoch===micEpoch){opening=false;label();}}
|
| 340 |
}
|
| 341 |
function micFailed(reason="mic_error"){
|
|
|
|
| 342 |
micIssue=reason;
|
| 343 |
if(reason==="mic_error")pauseMic();else release();
|
| 344 |
if(!busy && !stopped)setStatus(reason);
|
| 345 |
}
|
| 346 |
function endSession(){
|
|
|
|
| 347 |
if(opening&&!take){release();setStatus("idle");return;}
|
| 348 |
if(!take||stopped)return;timeline?.close();stopped=true;retryKind="";queue=[];voiceDraft=new Int16Array(0);playback.clear();release();setStatus("stopping");emit("halt",{take});
|
| 349 |
clearTimeout(watchdog);watchdog=setTimeout(()=>{if(stopped)finish("connection");},40000);
|
| 350 |
}
|
| 351 |
mic.addEventListener("click",()=>{
|
| 352 |
-
if(stream)pauseMic();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
});
|
| 354 |
by("send-voice").addEventListener("click",()=>{
|
| 355 |
if(stream||opening||by("send-voice").disabled)return;
|
|
@@ -400,7 +472,7 @@ retry.addEventListener("click",()=>{
|
|
| 400 |
if(action==="playback" && lastSegment && !stopped){busy=true;setStatus("loading");playback.segment(lastSegment);return;}
|
| 401 |
if(action==="export"){setStatus("finalizing");emit("export_take",{take,device:collection?.device});return;}
|
| 402 |
if(action==="render" && take && !stopped){
|
| 403 |
-
busy=true;setStatus("renderPending");emit("roll",{take,stream_preview:true,rev:visionRev});
|
| 404 |
}
|
| 405 |
});
|
| 406 |
window.addEventListener("ffv-signal",e=>{
|
|
@@ -429,27 +501,27 @@ window.addEventListener("ffv-signal",e=>{
|
|
| 429 |
interpreter=d.interpreter||"";lastSource=d.source;
|
| 430 |
lastHeard=d.heard;prompt=d.summary;focus=d.focus;
|
| 431 |
if(d.phase==="clarify"){
|
| 432 |
-
questionId=d.question;queue=[];clearPhrase();busy=false;setStatus("clarify");return;
|
| 433 |
}
|
| 434 |
questionId=null;editOperation=d.operation||"append";
|
| 435 |
-
if(editOperation==="redo_last"){queue=[];clearPhrase();}
|
| 436 |
visionRev=d.rev;
|
| 437 |
setStatus("renderPending");emit("roll",{take,stream_preview:true,rev:d.rev});return;
|
| 438 |
}
|
| 439 |
if(d.phase==="question_cancelled"){
|
| 440 |
-
questionId=null;submittedDraft=null;inFlight=null;busy=false;setStatus("holding");pump();return;
|
| 441 |
}
|
| 442 |
if(d.phase==="decided"&&variantClip&&d.rev===variantClip.rev){
|
| 443 |
if(d.choice==="variant"){approvedClip=variantClip;timeline.add(approvedClip,true);}
|
| 444 |
variantClip=null;choosing=false;editOperation="append";retryKind="";
|
| 445 |
lastSegment=approvedClip;applied=approvedClip.rev;pendingStill=approvedClip.still;
|
| 446 |
({lastHeard,focus,prompt,interpreter,lastSource}=approvedClip);
|
| 447 |
-
hold.src=pendingStill;setMode("hold");playback.repeatClip(approvedClip);syncLoop();busy=false;setStatus("holding");pump();return;
|
| 448 |
}
|
| 449 |
if(d.phase==="decision_error"){choosing=false;busy=false;setStatus("decision_error");return;}
|
| 450 |
if(["ignored","empty","speech_error","locked_segment","invalid_text","invalid_seconds","invalid_target","invalid_operation"].includes(d.phase)){
|
| 451 |
if(inFlight?.operation==="redo_last"&&inFlight.target_rev===applied)forceRedo.checked=true;
|
| 452 |
-
submittedDraft=null;inFlight=null;busy=false;setStatus(d.phase==="ignored"?(applied?"holding":"armed"):d.phase);pump();return;
|
| 453 |
}
|
| 454 |
if(d.phase==="ignored_roll" || (d.rev && d.rev!==visionRev))return;
|
| 455 |
if(d.phase==="preview"){
|
|
@@ -466,6 +538,7 @@ window.addEventListener("ffv-signal",e=>{
|
|
| 466 |
return;
|
| 467 |
}
|
| 468 |
if(["gpu_error","quota","hardware","disk_full"].includes(d.phase)){
|
|
|
|
| 469 |
// A written direction queued against a failed segment stays in the editor.
|
| 470 |
if(queue.some(cue=>cue.text!==undefined)){
|
| 471 |
queue=queue.filter(cue=>cue.text===undefined);submittedDraft=null;
|
|
@@ -478,6 +551,7 @@ window.addEventListener("ffv-signal",e=>{
|
|
| 478 |
}
|
| 479 |
if(d.phase==="segment"||d.phase==="variant"){
|
| 480 |
if(d.rev<=applied||variantClip?.rev===d.rev)return;
|
|
|
|
| 481 |
const clip={thumb:d.thumb,media:d.media,preview:d.preview,frames:d.frames,still:d.still,rev:d.rev,seconds:d.seconds,lastHeard,prompt,focus,interpreter,lastSource};
|
| 482 |
if(d.phase==="variant")variantClip=clip;
|
| 483 |
else {approvedClip=clip;applied=d.rev;timeline.add(clip);}
|
|
@@ -490,6 +564,7 @@ window.addEventListener("ffv-signal",e=>{
|
|
| 490 |
playback.extend({...clip,preview:livePreview.path},Math.ceil(clip.frames/8));
|
| 491 |
}
|
| 492 |
}else{livePreview=null;displayClip(clip);}
|
|
|
|
| 493 |
return;
|
| 494 |
}
|
| 495 |
setStatus(d.phase==="generating"&&editOperation==="redo_last"?"redoGenerating":d.phase);
|
|
|
|
| 50 |
quietHint:["Speak in a quiet place. Pause for 3 seconds to send.","Parle dans un endroit calme. Une pause de 3 s envoie la consigne."],
|
| 51 |
pausedHint:["Mic off. Your direction is paused.","Micro coupé. Ta consigne est en pause."],
|
| 52 |
continueHint:["Continue your direction, then pause for 3 seconds to send.","Continue ta consigne, puis laisse 3 s de silence pour l’envoyer."],
|
| 53 |
+
autoPause:["Mic paused · automatic resume","Micro en pause · reprise automatique"],
|
| 54 |
+
stayMuted:["Keep muted","Garder coupé"],listenWhenReady:["Listen when ready","Activer à la reprise"],
|
| 55 |
+
dictateNext:["Dictate next direction","Dicter la suite"],nextListening:["Listening for your next direction.","À l’écoute de ta prochaine consigne."],
|
| 56 |
+
queuedVoice:["Next direction queued.","Prochaine consigne en attente."],
|
| 57 |
+
liveHint:["Listening · pause for 3 seconds to send.","À l’écoute · une pause de 3 s envoie la consigne."],
|
| 58 |
resumeVoice:["Resume","Reprendre"],sendVoice:["Send","Envoyer"],discardVoice:["Discard","Effacer"],
|
| 59 |
phraseTooLong:["Direction too long. Unmute and try a shorter cue (up to 45 seconds).","Consigne trop longue. Réactive le micro et réessaie en 45 secondes maximum."],
|
| 60 |
framesReady:["frames available","images disponibles"],
|
|
|
|
| 94 |
let inputMode = "voice", lastSource = "", interpreter = "", submittedDraft = null;
|
| 95 |
let take = null, status = "idle", mode = "idle", focus="", prompt="", lastHeard="";
|
| 96 |
let stream=null, ctx=null, node=null, opening=false, stopped=false, micEpoch=0, micIssue="";
|
| 97 |
+
let idleAudioContext=null, micSource=null, silentOutput=null;
|
| 98 |
+
const workletContexts=new WeakSet();
|
| 99 |
+
let processing=false, listenAfterCue=false, dictatingNext=false;
|
| 100 |
let ready=false, busy=false, saved=false, seq=0, applied=0, visionRev=0, retryKind="", pendingStill="", lastSegment=null;
|
| 101 |
let approvedClip=null, variantClip=null, questionId=null, inFlight=null, choosing=false, editOperation="append";
|
| 102 |
let queue=[], pre=[], blocks=[], voice=false, quiet=0, loud=0, baseline=.003, watchdog=0;
|
|
|
|
| 116 |
try{localStorage.setItem("ffv-loop",loopEnabled?"on":"off");}catch{}
|
| 117 |
syncLoop();label();
|
| 118 |
});
|
| 119 |
+
document.addEventListener?.("visibilitychange",()=>{
|
| 120 |
+
if(document.hidden && (listenAfterCue || dictatingNext || opening || stream))pauseMic();
|
| 121 |
+
syncLoop();
|
| 122 |
+
});
|
| 123 |
syncLoop();
|
| 124 |
const workingStages=new Set(["permission","starting","sent","transcribing","interpreting","renderPending","queued","allocated","restoring","generating","redoGenerating","saving","encoding","loading","deciding","stopping","finalizing","archiving"]);
|
| 125 |
const errorStages=new Set(["mic_error","phraseTooLong","empty","speech_error","quota","gpu_error","hardware","connection","disk_full","expired","play_error","export_error","archive_error","decision_error","invalid_model","invalid_target","invalid_operation","invalid_seconds","invalid_text","locked_segment","history_error"]);
|
|
|
|
| 149 |
root.querySelectorAll("[data-aria-fr]").forEach(e=>e.setAttribute("aria-label",lang==="fr"?e.dataset.ariaFr:e.dataset.ariaEn));
|
| 150 |
root.querySelectorAll("[data-tr]").forEach(e=>e.textContent=tr(e.dataset.tr));
|
| 151 |
langButtons.forEach((b,i)=>b.setAttribute("aria-pressed",String(i===(lang==="fr"?1:0))));
|
| 152 |
+
const waitingForWork=Boolean(processing || variantClip || queue.length);
|
| 153 |
+
let micWord=voiceDraft.length?"resumeVoice":"off";
|
| 154 |
+
if(waitingForWork)micWord=listenAfterCue?"stayMuted":"listenWhenReady";
|
| 155 |
+
if(!take)micWord="start";
|
| 156 |
+
if(stream)micWord="on";
|
| 157 |
+
if(opening)micWord="cancel";
|
| 158 |
+
by("mic-word").textContent=tr(micWord);
|
| 159 |
by("mode-voice").setAttribute("aria-pressed",String(inputMode==="voice"));
|
| 160 |
by("mode-text").setAttribute("aria-pressed",String(inputMode==="text"));
|
| 161 |
by("voice-control").hidden=inputMode!=="voice";
|
| 162 |
const paused=voiceDraft.length>0 && !stream && !stopped;
|
| 163 |
by("voice-draft-actions").hidden=!paused;
|
| 164 |
+
by("send-voice").disabled=opening||stopped||Boolean(variantClip)||queue.length>0||(busy && (editOperation==="redo_last"||Boolean(questionId)));
|
| 165 |
by("discard-voice").disabled=opening;
|
| 166 |
+
by("dictate-next").hidden=!canDictateNext() || Boolean(stream||opening);
|
| 167 |
+
let hint=stream?"liveHint":"quietHint";
|
| 168 |
+
if(waitingForWork&&!stream)hint=listenAfterCue?"autoPause":"muted";
|
| 169 |
+
if(voiceDraft.length)hint=stream?"continueHint":"pausedHint";
|
| 170 |
+
if(dictatingNext&&stream)hint="nextListening";
|
| 171 |
+
by("voice-hint").textContent=tr(micIssue||hint);
|
| 172 |
+
by("voice-queued").hidden=!queue.some(c=>c.samples);
|
| 173 |
by("text-control").hidden=inputMode!=="text";
|
| 174 |
deskEl.dataset.input=inputMode;
|
| 175 |
deskEl.dataset.active=String(Boolean(take));
|
|
|
|
| 201 |
const muted = Boolean(inputMode==="voice" && take && !stream && !opening && !stopped);
|
| 202 |
mic.dataset.micState = muted ? "muted" : stream ? "listening" : "idle";
|
| 203 |
retry.hidden=!retryKind;
|
| 204 |
+
mic.disabled=stopped;
|
| 205 |
end.disabled=(!take&&!opening)||stopped;
|
| 206 |
end.title=tr("endSave");
|
| 207 |
end.setAttribute("aria-label",tr("endSave"));
|
|
|
|
| 216 |
function setMode(m){mode=m;monitor.dataset.mode=m;}
|
| 217 |
function clearPhrase(){pre=[];blocks=[];voice=false;quiet=0;loud=0;phraseSeconds=0;baseline=.003;}
|
| 218 |
function draw(level=0){meter.clearRect(0,0,88,32);for(let i=0;i<12;i++){meter.fillStyle=level>i/12?"#ffb354":"#515854";const h=5+i*1.8;meter.fillRect(i*7,16-h/2,4,h);}}
|
| 219 |
+
function release(keepAudioContext=false){
|
| 220 |
micEpoch++;opening=false;
|
| 221 |
+
if(micSource){micSource.disconnect();micSource=null;}
|
| 222 |
if(node){if(node.port)node.port.onmessage=null;else node.onaudioprocess=null;node.disconnect();node=null;}
|
| 223 |
+
if(silentOutput){silentOutput.disconnect();silentOutput=null;}
|
| 224 |
if(stream){stream.getTracks().forEach(t=>t.stop());stream=null;}
|
| 225 |
+
if(ctx){idleAudioContext=ctx;ctx=null;}
|
| 226 |
+
if(!keepAudioContext && idleAudioContext){idleAudioContext.close().catch(()=>{});idleAudioContext=null;}
|
| 227 |
clearPhrase();draw();label();
|
| 228 |
}
|
| 229 |
function pauseMic(){
|
| 230 |
+
listenAfterCue=false;dictatingNext=false;
|
| 231 |
retainSpeech();
|
| 232 |
release();
|
| 233 |
}
|
| 234 |
+
function pauseForWork(){
|
| 235 |
+
dictatingNext=false;
|
| 236 |
+
if(stream||opening){retainSpeech();release(listenAfterCue);}
|
| 237 |
+
}
|
| 238 |
+
function canDictateNext(){
|
| 239 |
+
return processing && take && !stopped && inputMode==="voice" && !queue.length && !variantClip && !questionId
|
| 240 |
+
&& (inFlight ? inFlight.operation!=="redo_last" && !inFlight.answer : editOperation==="append");
|
| 241 |
+
}
|
| 242 |
+
function resumeIfReady(){
|
| 243 |
+
if(listenAfterCue && !processing && !queue.length && !variantClip && take && ready && !stopped &&
|
| 244 |
+
!(questionId && voiceDraft.length) && inputMode==="voice" && !document.hidden &&
|
| 245 |
+
by("studio").dataset.view!=="gallery" && !stream && !opening)openMic();
|
| 246 |
+
}
|
| 247 |
+
function holdNextDirection(){
|
| 248 |
+
// A failed or ambiguous preceding cue gives a pre-dictated direction back to its author.
|
| 249 |
+
const pending=queue.find(c=>c.samples);
|
| 250 |
+
if(dictatingNext || pending){
|
| 251 |
+
pauseMic();
|
| 252 |
+
if(pending){voiceDraft=pending.samples;queue=queue.filter(c=>c!==pending);}
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
function resetEditing(){
|
| 256 |
+
processing=false;dictatingNext=false;
|
| 257 |
livePreview=null;
|
| 258 |
voiceDraft=new Int16Array(0);
|
| 259 |
approvedClip=variantClip=questionId=inFlight=null;choosing=false;editOperation="append";forceRedo.checked=false;
|
| 260 |
}
|
| 261 |
function finish(k){
|
| 262 |
+
listenAfterCue=false;
|
| 263 |
resetEditing();
|
| 264 |
clearTimeout(watchdog); submittedDraft=null;release();queue=[];take=null;ready=false;busy=false;retryKind="";stopped=false;playback.clear();
|
| 265 |
if(k==="finished")saved=true;
|
|
|
|
| 289 |
}
|
| 290 |
forceRedo.addEventListener("change",label);
|
| 291 |
function pump(){if(!take||!ready||busy||stopped||variantClip||!queue.length)return;timeline?.close();busy=true;retryKind="";
|
| 292 |
+
const {samples,...cue}=queue.shift(), written=cue.text!==undefined;
|
| 293 |
+
processing=true;pauseForWork();
|
| 294 |
inFlight=cue;setStatus("sent");
|
| 295 |
+
emit(written?"written":"phrase",{take,seq:++seq,...cue,...(samples?{audio:pack(samples)}:{})});
|
| 296 |
}
|
| 297 |
function retainSpeech(){
|
| 298 |
if(!voice || !blocks.length || !ctx || loud<=.16)return false;
|
|
|
|
| 306 |
return true;
|
| 307 |
}
|
| 308 |
function submitVoice(){
|
| 309 |
+
if(!voiceDraft.length || !take || stopped || variantClip || queue.length)return;
|
| 310 |
+
queue.push({samples:voiceDraft,...cueOptions()});
|
| 311 |
voiceDraft=new Int16Array(0);
|
| 312 |
+
pauseForWork();
|
| 313 |
label();pump();
|
| 314 |
}
|
| 315 |
function flush(){
|
|
|
|
| 318 |
if(fresh)submitVoice();
|
| 319 |
}
|
| 320 |
function sample(a){
|
| 321 |
+
if(!ctx||!take||stopped||variantClip||queue.length||(processing&&!dictatingNext))return;
|
| 322 |
const dt=a.length/ctx.sampleRate;let sum=0;for(const x of a)sum+=x*x;
|
| 323 |
const rms=Math.sqrt(sum/a.length);draw(Math.min(1,rms*9));
|
| 324 |
const sound=rms>Math.max(.008,baseline*3.2);
|
|
|
|
| 340 |
}
|
| 341 |
function chooseInput(next){
|
| 342 |
inputMode=next;
|
| 343 |
+
if(next==="text")pauseMic();
|
| 344 |
label();
|
| 345 |
if(next==="text")draft.focus();
|
| 346 |
}
|
|
|
|
| 361 |
if(e.key==="Enter"&&!e.shiftKey&&!e.isComposing){e.preventDefault();sendWritten();}
|
| 362 |
});
|
| 363 |
async function openMic(){
|
| 364 |
+
if(opening||stream||stopped||inputMode!=="voice"||document.hidden)return;
|
| 365 |
micIssue="";opening=true;const epoch=++micEpoch;
|
| 366 |
label();
|
| 367 |
try{
|
| 368 |
const capture=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:true,noiseSuppression:true},video:false});
|
| 369 |
if(epoch!==micEpoch){capture.getTracks().forEach(t=>t.stop());return;}
|
| 370 |
+
// Reuse the user-activated audio context on mobile, with a fresh input track for every capture.
|
| 371 |
+
stream=capture;const activeContext=idleAudioContext||new AudioContext();idleAudioContext=null;ctx=activeContext;
|
| 372 |
+
let resumeTimer;
|
| 373 |
+
try{
|
| 374 |
+
await Promise.race([activeContext.resume(),new Promise((_,reject)=>{resumeTimer=setTimeout(()=>reject(new Error("Audio input paused")),4000);})]);
|
| 375 |
+
}finally{clearTimeout(resumeTimer);}
|
| 376 |
if(epoch!==micEpoch)return;
|
| 377 |
const moduleSource = /* WORKLET_MODULE */ "";
|
| 378 |
+
let moduleURL,timer;
|
|
|
|
| 379 |
try{
|
| 380 |
+
if(!workletContexts.has(activeContext)){
|
| 381 |
+
moduleURL=URL.createObjectURL(new Blob([moduleSource],{type:"text/javascript"}));
|
| 382 |
+
await Promise.race([activeContext.audioWorklet.addModule(moduleURL),new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error("worklet timeout")),2500);})]);
|
| 383 |
+
workletContexts.add(activeContext);
|
| 384 |
+
}
|
| 385 |
if(epoch!==micEpoch)return;
|
| 386 |
node=new AudioWorkletNode(activeContext,"ffv-capture");
|
| 387 |
node.port.onmessage=e=>{if(epoch===micEpoch)sample(e.data);};
|
|
|
|
| 389 |
if(epoch!==micEpoch)return;
|
| 390 |
node=activeContext.createScriptProcessor(1024,1,1);
|
| 391 |
node.onaudioprocess=e=>{if(epoch===micEpoch)sample(new Float32Array(e.inputBuffer.getChannelData(0)));};
|
| 392 |
+
}finally{clearTimeout(timer);if(moduleURL)URL.revokeObjectURL(moduleURL);}
|
| 393 |
+
micSource=ctx.createMediaStreamSource(capture);
|
| 394 |
+
silentOutput=ctx.createGain();silentOutput.gain.value=0;micSource.connect(node);node.connect(silentOutput);silentOutput.connect(ctx.destination);
|
| 395 |
capture.getAudioTracks()[0].addEventListener("ended",()=>{if(capture===stream)micFailed();});
|
| 396 |
if(!take)startTake();
|
| 397 |
if (status==="mic_error" || status==="phraseTooLong") setStatus(applied?"holding":"armed");
|
|
|
|
| 399 |
finally{if(epoch===micEpoch){opening=false;label();}}
|
| 400 |
}
|
| 401 |
function micFailed(reason="mic_error"){
|
| 402 |
+
listenAfterCue=false;dictatingNext=false;
|
| 403 |
micIssue=reason;
|
| 404 |
if(reason==="mic_error")pauseMic();else release();
|
| 405 |
if(!busy && !stopped)setStatus(reason);
|
| 406 |
}
|
| 407 |
function endSession(){
|
| 408 |
+
listenAfterCue=false;dictatingNext=false;processing=false;
|
| 409 |
if(opening&&!take){release();setStatus("idle");return;}
|
| 410 |
if(!take||stopped)return;timeline?.close();stopped=true;retryKind="";queue=[];voiceDraft=new Int16Array(0);playback.clear();release();setStatus("stopping");emit("halt",{take});
|
| 411 |
clearTimeout(watchdog);watchdog=setTimeout(()=>{if(stopped)finish("connection");},40000);
|
| 412 |
}
|
| 413 |
mic.addEventListener("click",()=>{
|
| 414 |
+
if(stream||opening){pauseMic();return;}
|
| 415 |
+
if(processing||variantClip||queue.length){
|
| 416 |
+
if(listenAfterCue)pauseMic();
|
| 417 |
+
else{listenAfterCue=true;micIssue="";label();}
|
| 418 |
+
return;
|
| 419 |
+
}
|
| 420 |
+
listenAfterCue=true;openMic();
|
| 421 |
+
});
|
| 422 |
+
by("dictate-next").addEventListener("click",()=>{
|
| 423 |
+
if(!canDictateNext()||opening||stream)return;
|
| 424 |
+
dictatingNext=true;openMic();
|
| 425 |
});
|
| 426 |
by("send-voice").addEventListener("click",()=>{
|
| 427 |
if(stream||opening||by("send-voice").disabled)return;
|
|
|
|
| 472 |
if(action==="playback" && lastSegment && !stopped){busy=true;setStatus("loading");playback.segment(lastSegment);return;}
|
| 473 |
if(action==="export"){setStatus("finalizing");emit("export_take",{take,device:collection?.device});return;}
|
| 474 |
if(action==="render" && take && !stopped){
|
| 475 |
+
processing=true;busy=true;pauseForWork();setStatus("renderPending");emit("roll",{take,stream_preview:true,rev:visionRev});
|
| 476 |
}
|
| 477 |
});
|
| 478 |
window.addEventListener("ffv-signal",e=>{
|
|
|
|
| 501 |
interpreter=d.interpreter||"";lastSource=d.source;
|
| 502 |
lastHeard=d.heard;prompt=d.summary;focus=d.focus;
|
| 503 |
if(d.phase==="clarify"){
|
| 504 |
+
holdNextDirection();processing=false;questionId=d.question;queue=[];clearPhrase();busy=false;setStatus("clarify");resumeIfReady();return;
|
| 505 |
}
|
| 506 |
questionId=null;editOperation=d.operation||"append";
|
| 507 |
+
if(editOperation==="redo_last"){holdNextDirection();pauseForWork();queue=[];clearPhrase();}
|
| 508 |
visionRev=d.rev;
|
| 509 |
setStatus("renderPending");emit("roll",{take,stream_preview:true,rev:d.rev});return;
|
| 510 |
}
|
| 511 |
if(d.phase==="question_cancelled"){
|
| 512 |
+
processing=false;questionId=null;submittedDraft=null;inFlight=null;busy=false;setStatus("holding");pump();resumeIfReady();return;
|
| 513 |
}
|
| 514 |
if(d.phase==="decided"&&variantClip&&d.rev===variantClip.rev){
|
| 515 |
if(d.choice==="variant"){approvedClip=variantClip;timeline.add(approvedClip,true);}
|
| 516 |
variantClip=null;choosing=false;editOperation="append";retryKind="";
|
| 517 |
lastSegment=approvedClip;applied=approvedClip.rev;pendingStill=approvedClip.still;
|
| 518 |
({lastHeard,focus,prompt,interpreter,lastSource}=approvedClip);
|
| 519 |
+
hold.src=pendingStill;setMode("hold");playback.repeatClip(approvedClip);syncLoop();busy=false;setStatus("holding");pump();resumeIfReady();return;
|
| 520 |
}
|
| 521 |
if(d.phase==="decision_error"){choosing=false;busy=false;setStatus("decision_error");return;}
|
| 522 |
if(["ignored","empty","speech_error","locked_segment","invalid_text","invalid_seconds","invalid_target","invalid_operation"].includes(d.phase)){
|
| 523 |
if(inFlight?.operation==="redo_last"&&inFlight.target_rev===applied)forceRedo.checked=true;
|
| 524 |
+
holdNextDirection();pauseMic();processing=false;submittedDraft=null;inFlight=null;busy=false;setStatus(d.phase==="ignored"?(applied?"holding":"armed"):d.phase);pump();return;
|
| 525 |
}
|
| 526 |
if(d.phase==="ignored_roll" || (d.rev && d.rev!==visionRev))return;
|
| 527 |
if(d.phase==="preview"){
|
|
|
|
| 538 |
return;
|
| 539 |
}
|
| 540 |
if(["gpu_error","quota","hardware","disk_full"].includes(d.phase)){
|
| 541 |
+
holdNextDirection();pauseMic();processing=false;
|
| 542 |
// A written direction queued against a failed segment stays in the editor.
|
| 543 |
if(queue.some(cue=>cue.text!==undefined)){
|
| 544 |
queue=queue.filter(cue=>cue.text===undefined);submittedDraft=null;
|
|
|
|
| 551 |
}
|
| 552 |
if(d.phase==="segment"||d.phase==="variant"){
|
| 553 |
if(d.rev<=applied||variantClip?.rev===d.rev)return;
|
| 554 |
+
processing=false;
|
| 555 |
const clip={thumb:d.thumb,media:d.media,preview:d.preview,frames:d.frames,still:d.still,rev:d.rev,seconds:d.seconds,lastHeard,prompt,focus,interpreter,lastSource};
|
| 556 |
if(d.phase==="variant")variantClip=clip;
|
| 557 |
else {approvedClip=clip;applied=d.rev;timeline.add(clip);}
|
|
|
|
| 564 |
playback.extend({...clip,preview:livePreview.path},Math.ceil(clip.frames/8));
|
| 565 |
}
|
| 566 |
}else{livePreview=null;displayClip(clip);}
|
| 567 |
+
label();resumeIfReady();
|
| 568 |
return;
|
| 569 |
}
|
| 570 |
setStatus(d.phase==="generating"&&editOperation==="redo_last"?"redoGenerating":d.phase);
|