Spaces:
Running
Running
| import{r as t,j as e}from"./react-D_B_5QVd.js";import{U as y,V as v,L as h,M as N}from"./index-BdwitBZy.js";import{a as R}from"./fileUtils-Dvg4vqd5.js";import"./jszip-C9ownNzX.js";import"./react-dom-EAO2-NBm.js";import"./scheduler-DYLXRpC5.js";import"./@google-4tyssLU_.js";import"./marked-CesSW9Du.js";import"./idb-Dob3nYDb.js";const B=()=>{const[o,x]=t.useState(!1),[n,d]=t.useState(!1),[c,f]=t.useState(""),[u,i]=t.useState(""),r=t.useRef(null),l=t.useRef([]),g=async()=>{if(i(""),f(""),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){i("Audio recording is not supported by your browser.");return}try{const s=await navigator.mediaDevices.getUserMedia({audio:!0});r.current=new MediaRecorder(s),r.current.ondataavailable=a=>{l.current.push(a.data)},r.current.onstop=j,r.current.start(),x(!0)}catch{i("Microphone access was denied. Please enable it in your browser settings.")}},b=()=>{r.current&&o&&(r.current.stop(),r.current.stream.getTracks().forEach(s=>s.stop()),x(!1),d(!0))},j=t.useCallback(async()=>{if(l.current.length===0){d(!1);return}const s=new Blob(l.current,{type:"audio/webm"});l.current=[];try{const a=await R(s),m=y(a,"audio/webm");let p="";for await(const w of m)p+=w,f(p)}catch(a){const m=a instanceof Error?a.message:"An unknown error occurred.";i(`Failed to transcribe audio: ${m}`)}finally{d(!1)}},[]);return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6 text-center",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center justify-center",children:[e.jsx(v,{}),e.jsx("span",{className:"ml-3",children:"AI Audio-to-Code"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Speak your programming ideas and watch them turn into code."})]}),e.jsxs("div",{className:"flex-grow flex flex-col items-center gap-6 min-h-0",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center bg-surface p-6 rounded-lg w-full max-w-lg border border-border",children:[e.jsx("button",{onClick:o?b:g,className:`w-24 h-24 rounded-full flex items-center justify-center text-white font-bold text-lg transition-all ${o?"bg-red-500 animate-pulse":"bg-primary"}`,disabled:n,children:n?e.jsx(h,{}):o?"Stop":"Record"}),e.jsx("p",{className:"mt-4 text-text-secondary",children:n?"Transcribing...":o?"Recording in progress...":"Click to start recording"})]}),e.jsxs("div",{className:"flex flex-col h-full w-full max-w-3xl",children:[e.jsx("label",{className:"text-sm font-medium text-text-secondary mb-2",children:"Generated Code"}),e.jsxs("div",{className:"flex-grow p-1 bg-background border border-border rounded-md overflow-y-auto min-h-[200px]",children:[n&&!c&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(h,{})}),u&&e.jsx("p",{className:"p-4 text-red-500",children:u}),c&&e.jsx(N,{content:c}),!n&&!c&&!u&&e.jsx("div",{className:"text-text-secondary h-full flex items-center justify-center",children:"Code will appear here."})]})]})]})]})};export{B as AudioToCode}; | |
| //# sourceMappingURL=AudioToCode-D6DCpAJs.js.map | |