Upload index.html
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Voicebox AI • Browser TTS</title><style>*{box-sizing:border-box}body{margin:0;background:#07090e;color:#f7f8fb;font-family:Inter,Arial,sans-serif}.wrap{max-width:1120px;margin:auto;padding:28px}.nav{display:flex;justify-content:space-between;align-items:center}.logo{font-weight:850;font-size:21px}.pill{font-size:12px;color:#9ea8b7;border:1px solid #29303b;border-radius:99px;padding:7px 11px}.hero{text-align:center;padding:70px 0 32px}.hero h1{font-size:52px;line-height:1.02;letter-spacing:-2px;margin:0 0 14px}.hero p{max-width:720px;margin:auto;color:#aab2bf;line-height:1.65}.card{background:#10131a;border:1px solid #252b35;border-radius:22px;padding:25px;margin-top:23px;box-shadow:0 18px 60px #0006}.grid{display:grid;grid-template-columns:1.7fr 1fr;gap:20px}label{display:block;font-size:13px;color:#cbd2dc;margin:0 0 9px}textarea,select{width:100%;background:#090b10;color:#fff;border:1px solid #2a313c;border-radius:13px;padding:14px;font-size:15px}textarea{min-height:200px;resize:vertical}.speedrow{display:flex;gap:12px;align-items:center}.speedrow input{width:100%}button{width:100%;margin-top:15px;padding:15px;border:0;border-radius:13px;background:#fff;color:#080a0f;font-weight:850;cursor:pointer}button:disabled{opacity:.55;cursor:wait}.status{display:none;margin-top:13px;background:#171b23;border-radius:12px;padding:13px;color:#bcc4cf;font-size:13px;line-height:1.5}.preview{min-height:220px;border:1px dashed #303744;border-radius:16px;padding:24px}.preview.empty{display:flex;align-items:center;justify-content:center;text-align:center;color:#6d7786}audio{width:100%;margin-top:5px}.download{display:none;margin-top:12px;text-decoration:none;text-align:center;padding:12px;border-radius:12px;background:#171b23;color:#fff;border:1px solid #303744;font-weight:750}.meta{font-size:12px;color:#727d8d;line-height:1.55;margin-top:12px}.footer{text-align:center;color:#667181;font-size:12px;padding:35px}@media(max-width:800px){.grid{grid-template-columns:1fr}.hero h1{font-size:40px}}</style></head><body><div class="wrap"><div class="nav"><div class="logo">🎙️ VOICEBOX AI</div><div class="pill">100% Browser TTS</div></div><section class="hero"><h1>Natural speech, directly in your browser.</h1><p>No API key. No paid GPU. No server-side inference. Kokoro runs inside your browser using WebGPU when available, with a WASM fallback.</p></section><div class="card"><div class="grid"><div><label>TEXT</label><textarea id="text">Welcome to our company. We are pleased to introduce our services.</textarea><div class="meta">The first generation fetches the AI model into your browser cache. You do not need to install or manually download anything.</div></div><div><label>VOICE</label><select id="voice"><option value="af_heart">Heart</option><option value="af_bella">Bella</option><option value="af_nicole">Nicole</option><option value="af_sarah">Sarah</option><option value="af_nova">Nova</option><option value="af_sky">Sky</option><option value="am_adam">Adam</option><option value="am_michael">Michael</option><option value="am_fenrir">Fenrir</option><option value="am_puck">Puck</option><option value="bf_emma">Emma</option><option value="bf_isabella">Isabella</option><option value="bf_alice">Alice</option><option value="bf_lily">Lily</option><option value="bm_george">George</option><option value="bm_fable">Fable</option><option value="bm_lewis">Lewis</option><option value="bm_daniel">Daniel</option></select><label style="margin-top:16px">SPEED</label><div class="speedrow"><input id="speed" type="range" min=".5" max="2" value="1" step=".1"><span id="speedValue">1.0×</span></div><button id="generate">✨ Generate Speech</button><div class="status" id="status"></div></div></div></div><div class="card"><label>OUTPUT AUDIO</label><div class="preview empty" id="preview"><div>🎧<br><br>Your generated audio will appear here.</div></div><a id="download" class="download" download="voicebox-kokoro.wav">⬇ Download WAV</a></div><div class="footer">Powered by Kokoro-82M • Browser inference • No server API required</div></div><script type="module">import { KokoroTTS } from "https://esm.sh/kokoro-js@1.2.1";const MODEL_ID="onnx-community/Kokoro-82M-v1.0-ONNX"; let tts=null, loading=null, currentUrl=null;const $=id=>document.getElementById(id);function status(msg,show=true){$("status").style.display=show?"block":"none";$("status").textContent=msg;}$("speed").addEventListener("input",e=>$("speedValue").textContent=Number(e.target.value).toFixed(1)+"×");async function getTTS(){if(tts)return tts;if(loading)return loading;loading=(async()=>{status("Loading Kokoro AI model into your browser. The first load can take a few minutes...");let device="wasm";try{if(navigator.gpu){const a=await navigator.gpu.requestAdapter();if(a)device="webgpu";}}catch(_){}status("Preparing Kokoro ("+device.toUpperCase()+")...");return tts=await KokoroTTS.from_pretrained(MODEL_ID,{dtype:device==="webgpu"?"fp32":"q8",device});})();try{return await loading}finally{loading=null}}$("generate").addEventListener("click",async()=>{const text=$("text").value.trim(),voice=$("voice").value,speed=Number($("speed").value),btn=$("generate");if(!text){alert("Please enter some text.");return} if(text.length>5000){alert("Please keep the text below 5,000 characters.");return}btn.disabled=true;$("preview").classList.add("empty");$("preview").innerHTML="<div>⏳ Generating speech...</div>";$("download").style.display="none";try{const model=await getTTS();status("Generating speech. This happens entirely in your browser...");const audio=await model.generate(text,{voice,speed});const blob=audio.toBlob();if(!blob)throw new Error("No audio blob returned.");if(currentUrl)URL.revokeObjectURL(currentUrl);currentUrl=URL.createObjectURL(blob);$("preview").classList.remove("empty");$("preview").innerHTML="";const player=document.createElement("audio");player.controls=true;player.src=currentUrl;player.autoplay=true;$("preview").appendChild(player);$("download").href=currentUrl;$("download").style.display="block";status("Done. Your audio was generated locally in the browser.");}catch(err){console.error(err);$("preview").classList.add("empty");$("preview").innerHTML="<div>⚠️ Generation failed.<br><br>Try Chrome or Edge, refresh the page, and try again.</div>";status("Error: "+(err?.message||String(err)));}finally{btn.disabled=false}});</script></body></html>123456789101112131415161718192021<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Voicebox AI • Free Browser TTS</title><style>*{box-sizing:border-box}body{margin:0;background:#07090e;color:#f7f8fb;font-family:Inter,Arial,sans-serif}.wrap{max-width:1120px;margin:auto;padding:28px}.nav{display:flex;justify-content:space-between;align-items:center}.logo{font-weight:850;font-size:21px}.pill{font-size:12px;color:#9ea8b7;border:1px solid #29303b;border-radius:99px;padding:7px 11px}.hero{text-align:center;padding:65px 0 30px}.hero h1{font-size:50px;line-height:1.02;letter-spacing:-2px;margin:0 0 14px}.hero p{max-width:720px;margin:auto;color:#aab2bf;line-height:1.65}.card{background:#10131a;border:1px solid #252b35;border-radius:22px;padding:25px;margin-top:23px;box-shadow:0 18px 60px #0006}.grid{display:grid;grid-template-columns:1.7fr 1fr;gap:20px}label{display:block;font-size:13px;color:#cbd2dc;margin:0 0 9px}textarea,select{width:100%;background:#090b10;color:#fff;border:1px solid #2a313c;border-radius:13px;padding:14px;font-size:15px}textarea{min-height:200px;resize:vertical}.speedrow{display:flex;gap:12px;align-items:center}.speedrow input{width:100%}button{width:100%;margin-top:15px;padding:15px;border:0;border-radius:13px;background:#fff;color:#080a0f;font-weight:850;cursor:pointer}button:disabled{opacity:.55;cursor:wait}.status{display:none;margin-top:13px;background:#171b23;border-radius:12px;padding:13px;color:#bcc4cf;font-size:13px;line-height:1.55}.preview{min-height:220px;border:1px dashed #303744;border-radius:16px;padding:24px}.preview.empty{display:flex;align-items:center;justify-content:center;text-align:center;color:#6d7786}audio{width:100%;margin-top:5px}.download{display:none;margin-top:12px;text-decoration:none;text-align:center;padding:12px;border-radius:12px;background:#171b23;color:#fff;border:1px solid #303744;font-weight:750}.meta{font-size:12px;color:#727d8d;line-height:1.55;margin-top:12px}.footer{text-align:center;color:#667181;font-size:12px;padding:35px}.warn{display:none;margin-top:10px;color:#e9c46a;font-size:12px}@media(max-width:800px){.grid{grid-template-columns:1fr}.hero h1{font-size:40px}}</style></head><body><div class="wrap"><div class="nav"><div class="logo">🎙️ VOICEBOX AI</div><div class="pill">Free • Browser TTS</div></div><section class="hero"><h1>Natural speech, without a paid server.</h1><p>Kokoro runs in your browser. This version deliberately uses the lightweight quantized WASM engine instead of WebGPU so it does not get stuck loading a huge FP32 model.</p></section><div class="card"><div class="grid"><div><label>TEXT</label><textarea id="text">Welcome to our company. We are pleased to introduce our services.</textarea><div class="meta">The first run downloads the quantized Kokoro model to your browser cache. Keep the first test short.</div></div><div><label>VOICE</label><select id="voice"><option value="af_bella">Bella</option><option value="af_nicole">Nicole</option><option value="af_sarah">Sarah</option><option value="af_nova">Nova</option><option value="af_sky">Sky</option><option value="af_heart">Heart</option><option value="am_adam">Adam</option><option value="am_michael">Michael</option><option value="bf_emma">Emma</option><option value="bf_isabella">Isabella</option><option value="bf_alice">Alice</option><option value="bm_george">George</option><option value="bm_fable">Fable</option><option value="bm_lewis">Lewis</option></select><label style="margin-top:16px">SPEED</label><div class="speedrow"><input id="speed" type="range" min=".7" max="1.3" value="1" step=".1"><span id="speedValue">1.0×</span></div><button id="generate">✨ Generate Speech</button><div class="status" id="status"></div><div class="warn" id="warn">If nothing happens after 5 minutes, refresh the page and try Chrome/Edge.</div></div></div></div><div class="card"><label>OUTPUT AUDIO</label><div class="preview empty" id="preview"><div>🎧<br><br>Your generated audio will appear here.</div></div><a id="download" class="download" download="voicebox-kokoro.wav">⬇ Download WAV</a></div><div class="footer">Kokoro-82M • q8 WASM • Browser inference • No API key • No paid GPU</div></div><script type="module">import { KokoroTTS } from "https://esm.sh/kokoro-js@1.2.1";const MODEL_ID="onnx-community/Kokoro-82M-v1.0-ONNX";let tts=null,loading=null,objectUrl=null;const $=id=>document.getElementById(id);const setStatus=m=>{$("status").style.display="block";$("status").textContent=m};$("speed").addEventListener("input",e=>$("speedValue").textContent=Number(e.target.value).toFixed(1)+"×");async function loadModel(){if(tts)return tts;if(loading)return loading;loading=(async()=>{setStatus("1/2 Loading Kokoro q8 model (WASM). First run can take a few minutes...");tts=await KokoroTTS.from_pretrained(MODEL_ID,{dtype:"q8",device:"wasm"});return tts})();try{return await loading}finally{loading=null}}$("generate").addEventListener("click",async()=>{const text=$("text").value.trim(),voice=$("voice").value,speed=Number($("speed").value),btn=$("generate");if(!text)return alert("Please enter some text.");if(text.length>1000)return alert("For the first test, keep the text below 1,000 characters.");btn.disabled=true;$("warn").style.display="block";$("preview").className="preview empty";$("preview").innerHTML="<div>⏳ Starting...</div>";$("download").style.display="none";try{const model=await loadModel();setStatus("2/2 Generating audio in your browser. Please wait...");const result=await model.generate(text,{voice,speed});const blob=result.toBlob();if(!blob)throw new Error("No audio was produced.");if(objectUrl)URL.revokeObjectURL(objectUrl);objectUrl=URL.createObjectURL(blob);$("preview").className="preview";$("preview").innerHTML="";const audio=document.createElement("audio");audio.controls=true;audio.autoplay=true;audio.src=objectUrl;$("preview").appendChild(audio);$("download").href=objectUrl;$("download").style.display="block";setStatus("✓ Done. Audio generated in your browser.");}catch(e){console.error(e);$("preview").className="preview empty";$("preview").innerHTML="<div>⚠️ Generation failed.<br><br>"+String(e?.message||e).replace(/[<>&]/g,"")+"</div>";setStatus("The browser could not complete Kokoro. Refresh once and try again.");}finally{btn.disabled=false}});</script></body></html>
index.html+15-60