{"manifest":{"schemaVersion":1,"sdkVersion":"0.1.0","id":"sm.voiceover","version":"2.1.2","name":"Voiceover","description":"Generate, import, record, preview, and choose saved narration takes with the project audio library and timing context in a portable Voiceover workspace.","kind":"workspace","runtime":"capability","entry":"src/capability.json","license":"MIT","provenance":{"notice":"MIT License\n\nCopyright (c) 2026 StillMade contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"},"inputs":{"input":{"type":"script","primary":true,"role":"narration_script","description":"The reviewed narration script to speak."},"take":{"type":"audio","required":false,"description":"An uploaded narration take that can be selected without generation."},"library":{"type":"asset[]","context":"assets","required":false,"description":"Saved project media; the workspace shows audio takes only."},"timing":{"type":"transcript","context":"transcript","required":false,"description":"The saved timed transcript for narration alignment."}},"outputs":{"output":{"type":"audio","primary":true,"role":"narration_audio","description":"The stored canonical WAV narration take."}},"permissions":{"project":["context.assets.read","context.transcript.read","asset.read"],"capabilities":["audio.speech"],"network":[],"filesystem":[],"secrets":[],"desktop":["microphone.capture"]},"ui":[{"port":"input","control":"text"}]},"capability":{"schemaVersion":1,"operation":"audio.speech","text":{"$input":"input"},"output":"output"},"view":{"html":"<main class=\"voiceover\">\n  <header class=\"voiceover-heading\"><div><small>PORTABLE WORKSPACE</small><h1>Voiceover</h1><p>Generate, import, record, and choose the narration take used by the next Block.</p></div><output id=\"length\">0 words · about 0:00</output></header>\n  <section class=\"voiceover-layout\">\n    <div class=\"script-panel\">\n      <label for=\"script\">Narration script</label>\n      <textarea id=\"script\" rows=\"12\" maxlength=\"3800\" placeholder=\"Paste or connect a finished narration script…\"></textarea>\n      <div class=\"script-meta\"><span id=\"characters\">0 / 3,800 characters</span><button id=\"restore\" type=\"button\" disabled>Restore connected script</button></div>\n      <button id=\"generate\" data-stillmade-action=\"run\" type=\"button\" class=\"primary\" disabled>Generate voiceover</button>\n      <p class=\"note\">StillMade shows the voice, provider, payment method, and maximum credits before generation.</p>\n      <section class=\"source-card\"><h2>Import or record</h2><p>The imported audio picker appears above this workspace. Choose a file there, then use it here.</p><div class=\"button-row\"><button id=\"use-import\" type=\"button\" disabled>Use imported audio</button><button id=\"start-record\" type=\"button\">Record microphone</button><button id=\"stop-record\" type=\"button\" disabled>Stop and use recording</button><button id=\"cancel-record\" type=\"button\" disabled>Cancel</button></div></section>\n      <section class=\"source-card\"><h2>Project audio library</h2><div id=\"library\"><p>No saved project audio yet.</p></div></section>\n      <section class=\"source-card\"><h2>Timing</h2><p id=\"timing\">No timed transcript is saved for this project yet.</p></section>\n    </div>\n    <aside class=\"take-panel\" aria-label=\"Narration take\">\n      <small>CURRENT TAKE</small><div class=\"take-empty\" id=\"take-empty\"><strong>No take yet</strong><p>Generate, import, record, or choose a saved project take.</p></div>\n      <div class=\"take-ready\" id=\"take-ready\" hidden><audio id=\"audio\" controls></audio><dl><div><dt>Source</dt><dd id=\"source\">—</dd></div><div><dt>Duration</dt><dd id=\"duration\">—</dd></div></dl><p>The selected saved media reference is this Block’s typed audio output.</p></div>\n      <p id=\"status\" role=\"status\" aria-live=\"polite\">Add or connect a script to begin.</p>\n    </aside>\n  </section>\n</main>\n","css":".voiceover{box-sizing:border-box;min-height:100%;padding:24px;color:var(--fg);background:var(--bg);font-family:var(--font-body)}.voiceover-heading{display:flex;align-items:flex-end;justify-content:space-between;gap:20px;margin-bottom:24px;border-bottom:1px solid var(--border-tok);padding-bottom:18px}.voiceover h1{margin:3px 0 8px;font-family:var(--font-display);font-size:38px;font-style:italic;font-weight:200}.voiceover h2{margin:0 0 6px;font-size:16px}.voiceover p{color:var(--fg-muted);line-height:1.5}.voiceover small{display:block;color:var(--fg-subtle);font-size:10px;font-weight:700;letter-spacing:.08em}.voiceover output{color:var(--fg-subtle);font-size:12px}.voiceover-layout{display:grid;grid-template-columns:minmax(320px,1.4fr) minmax(250px,.8fr);gap:28px}.voiceover label{display:block;margin:0 0 8px;font-size:13px;font-weight:650}.voiceover textarea{box-sizing:border-box;width:100%;resize:vertical;padding:14px;border:1px solid var(--border-tok);border-radius:var(--r-3);color:var(--fg);background:var(--bg-elev-1);font:inherit;line-height:1.65}.voiceover button{min-height:44px;padding:10px 16px;border:1px solid var(--border-strong);border-radius:999px;color:var(--fg);background:var(--bg);font:inherit;cursor:pointer}.voiceover button:disabled{opacity:.45;cursor:default}.voiceover .primary{width:100%;margin-top:18px;color:var(--bg);background:var(--fg)}.voiceover button:focus-visible,.voiceover textarea:focus-visible,.voiceover audio:focus-visible{outline:2px solid var(--signal);outline-offset:2px}.script-meta,.button-row,.library-row{display:flex;align-items:center;gap:10px}.script-meta{justify-content:space-between;margin-top:8px;color:var(--fg-subtle);font-size:12px}.script-meta button{padding:6px 12px}.note{margin:9px 0;font-size:12px}.source-card{margin-top:16px;padding:14px;border:1px solid var(--border-tok);border-radius:var(--r-3);background:var(--bg-elev-1)}.source-card p{margin:4px 0 10px;font-size:12px}.button-row{flex-wrap:wrap}.library-row{justify-content:space-between;padding:9px 0;border-top:1px solid var(--divider)}.library-row div{min-width:0}.library-row strong{display:block}.take-panel{min-width:0;padding:18px;border:1px solid var(--border-tok);border-radius:var(--r-3);background:var(--bg-elev-1)}.take-empty{margin-top:28px;padding:22px 0;text-align:center}.take-ready{margin-top:20px}.take-ready audio{width:100%}.take-ready dl{display:grid;gap:8px;margin:18px 0}.take-ready dl div{display:flex;justify-content:space-between;gap:12px;border-bottom:1px solid var(--divider);padding-bottom:8px}.take-ready dt{color:var(--fg-muted)}.take-ready dd{margin:0;text-align:right}#status{min-height:24px;margin:20px 0 0}@media(max-width:720px){.voiceover{padding:16px}.voiceover-heading{align-items:flex-start;flex-direction:column}.voiceover-layout{grid-template-columns:minmax(0,1fr);gap:18px}}@media(max-width:430px){.button-row{display:grid;grid-template-columns:1fr}.button-row button{width:100%}}\n","javascript":"const script=document.getElementById('script');\nconst generate=document.getElementById('generate');\nconst restore=document.getElementById('restore');\nconst status=document.getElementById('status');\nconst length=document.getElementById('length');\nconst characters=document.getElementById('characters');\nconst takeEmpty=document.getElementById('take-empty');\nconst takeReady=document.getElementById('take-ready');\nconst audio=document.getElementById('audio');\nconst duration=document.getElementById('duration');\nconst source=document.getElementById('source');\nconst useImport=document.getElementById('use-import');\nconst startRecord=document.getElementById('start-record');\nconst stopRecord=document.getElementById('stop-record');\nconst cancelRecord=document.getElementById('cancel-record');\nconst timing=document.getElementById('timing');\nlet connected='';let busy=false;let revision=0;let imported=null;let library=[];let previewUrl='';let recording=false;\nconst scriptText=value=>value&&typeof value.text==='string'?value.text:'';\nconst clock=seconds=>{const total=Math.max(0,Math.round(Number(seconds)||0));return String(Math.floor(total/60))+':'+String(total%60).padStart(2,'0');};\nconst update=()=>{const text=script.value;const words=text.trim()?text.trim().split(/\\s+/).length:0;characters.textContent=String(text.length)+' / 3,800 characters';length.textContent=String(words)+(words===1?' word':' words')+' · about '+clock(words/2.5);generate.disabled=busy||!text.trim()||text.length>3800;restore.disabled=busy||text===connected;useImport.disabled=busy||!imported;startRecord.disabled=busy||recording;stopRecord.disabled=busy||!recording;cancelRecord.disabled=busy||!recording;};\nconst showTake=async(take,label)=>{if(previewUrl)StillMade.releaseMedia(previewUrl);const preview=await StillMade.previewMedia(take);previewUrl=preview.url;audio.src=preview.url;source.textContent=label;duration.textContent=take.duration?clock(take.duration):'Saved audio';takeEmpty.hidden=true;takeReady.hidden=false;};\nconst choose=async(take,label)=>{busy=true;update();status.textContent='Saving the selected take…';try{const result=await StillMade.useOutput({output:take});await showTake(result.output,label);status.textContent='Take selected. It is ready for the next Block.';}catch(error){status.textContent=error.message||'The take could not be selected.';}finally{busy=false;update();}};\nconst renderLibrary=()=>StillMade.render('library',library.length?library.map((take,index)=>({tag:'article',className:'library-row',children:[{tag:'div',children:[{tag:'strong',text:take.label||'Saved audio '+String(index+1)},{tag:'small',text:take.versionId?'Version '+take.versionId:'Saved project audio'}]},{tag:'button',action:'library:'+String(index),text:'Use take',disabled:busy}]})):[{tag:'p',text:'No saved project audio yet.'}]);\nStillMade.onAction(event=>{const index=Number(event.action.split(':')[1]);const take=library.find((item,position)=>position===index);if(take&&!busy)choose(take,take.label||'Project library');});\nStillMade.onInput(values=>{connected=scriptText(values.input);revision+=1;if(!script.value.trim())script.value=connected;imported=values.take&&values.take.kind==='audio'?values.take:null;library=Array.isArray(values.library)?values.library.filter(item=>item&&item.kind==='audio').slice(0,40):[];const words=values.timing&&Array.isArray(values.timing.words)?values.timing.words:[];timing.textContent=words.length?String(words.length)+' timed words · '+clock(words.at(-1).endMs/1000)+' total':'No timed transcript is saved for this project yet.';renderLibrary();status.textContent=script.value.trim()?'Ready to generate or choose a narration take.':'Add or connect a script to begin.';update();});\nscript.addEventListener('input',update);\nrestore.addEventListener('click',()=>{if(busy)return;script.value=connected;status.textContent=connected?'Connected script restored.':'No connected script is available.';update();});\nuseImport.addEventListener('click',()=>{if(imported&&!busy)choose(imported,'Imported audio');});\nstartRecord.addEventListener('click',async()=>{if(busy||recording)return;busy=true;update();try{await StillMade.desktop('record.start',{kind:'microphone'});recording=true;status.textContent='Recording. Press Stop when the take is complete.';}catch(error){status.textContent=error.message;}finally{busy=false;update();}});\nstopRecord.addEventListener('click',async()=>{if(busy||!recording)return;busy=true;update();try{const saved=await StillMade.desktop('record.stop');recording=false;await choose(saved.asset,'Microphone recording');}catch(error){status.textContent=error.message;busy=false;update();}});\ncancelRecord.addEventListener('click',async()=>{if(busy||!recording)return;busy=true;update();try{await StillMade.desktop('record.cancel');recording=false;status.textContent='Recording cancelled.';}catch(error){status.textContent=error.message;}finally{busy=false;update();}});\ngenerate.addEventListener('click',async()=>{if(busy)return;const text=script.value.trim();if(!text){status.textContent='Add a narration script first.';return;}if(text.length>3800){status.textContent='Shorten the script to 3,800 characters before generating.';return;}const started=revision;busy=true;update();status.textContent='Review the voice and maximum credit amount in StillMade to continue.';try{const result=await StillMade.run({input:{schemaVersion:1,text}});const take=result.output;if(!take||take.kind!=='audio'||typeof take.url!=='string')throw Error('No saved narration take was returned.');await showTake(take,'Generated voiceover');status.textContent=started===revision?'Narration ready. This saved take is the Block output.':'Narration ready for the script used when generation started.';}catch(error){status.textContent=error.message||'The narration take could not be generated.';}finally{busy=false;update();}});\nupdate();\n"},"tests":[{"name":"Short narration","input":{"input":{"schemaVersion":1,"text":"The lighthouse kept watch as the storm crossed the bay."}},"expectations":{"output":{"kind":"audio","format":"wav","minDuration":0.1,"maxDuration":30,"minBytes":46,"maxBytes":1500000}}},{"name":"Maximum practical narration","input":{"input":{"schemaVersion":1,"text":"Morning arrived quietly. By noon, the town square was full of music. The narration remains reviewed, bounded, and ready for a replacement take."}},"expectations":{"output":{"kind":"audio","format":"wav","minDuration":0.1,"maxDuration":45,"minBytes":46,"maxBytes":2200000}}}]}