From 4798efa02efaad753d51bbe0a07c388048275482 Mon Sep 17 00:00:00 2001 From: "suraj.shenoy.b@gmail.com" Date: Sat, 25 Jan 2025 10:35:45 -0600 Subject: [PATCH 1/4] Fix --- .../transcribe/__pycache__/app.cpython-39.pyc | Bin 1039 -> 1005 bytes src/app/api/transcribe/app.py | 3 +- src/app/api/transcribe/route.ts | 55 ------------------ 3 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 src/app/api/transcribe/route.ts diff --git a/src/app/api/transcribe/__pycache__/app.cpython-39.pyc b/src/app/api/transcribe/__pycache__/app.cpython-39.pyc index 423ad4bdd9c2e17fb0eb0895703873acbbea046c..9eeb5d62d4f4c538b6b9a4ed0bbb18b8b649601a 100644 GIT binary patch delta 185 zcmeC@c+1Y4$ji&c00c$cQ`3Vt@)j~O)=jQw^f6Z`VO_vh!?cjGmbr#Gg+-E~mL;5_ zgna=ANQ{voj|agvU`S!DVaa3+X3%7t%*7-nev73fwW8z}Z%I*NUU70!WZlKkh8>4 K3GvCdnN0u@Pbo0~ delta 241 zcmaFM-p|3C$ji&c00gG&Q`0Lq@)j~OwoR^Q^r_b { - const transcription = await model.transcribe(filePath); - return transcription.text; -} - -async function parseMultipartForm(req: NextRequest): Promise { - return new Promise((resolve, reject) => { - const multerMiddleware = upload.single("audio"); - multerMiddleware(req as any, {} as any, (error: any) => { - if (error) return reject(error); - resolve(req.file); - }); - }); -} - -export async function POST(req: NextRequest) { - try { - // Parse the incoming multipart form data - const file = await parseMultipartForm(req); - - if (!file) { - return NextResponse.json({ error: "No audio file provided" }, { status: 400 }); - } - - const filePath = file.path; - - // Transcribe the audio - const transcription = await transcribeAudio(filePath); - - // Clean up the uploaded file - await fs.unlink(filePath); - - return NextResponse.json({ transcription }); - } catch (error) { - console.error("Error during transcription:", error); - return NextResponse.json({ error: "Transcription failed" }, { status: 500 }); - } -} From a31a4d931bc38c556f42294bab94f9de2a848138 Mon Sep 17 00:00:00 2001 From: "suraj.shenoy.b@gmail.com" Date: Sat, 25 Jan 2025 10:50:19 -0600 Subject: [PATCH 2/4] Update --- src/app/(web)/transcribe/layout.tsx | 16 ---------------- .../transcribe/__pycache__/app.cpython-39.pyc | Bin 1005 -> 1005 bytes 2 files changed, 16 deletions(-) delete mode 100644 src/app/(web)/transcribe/layout.tsx diff --git a/src/app/(web)/transcribe/layout.tsx b/src/app/(web)/transcribe/layout.tsx deleted file mode 100644 index a14e64f..0000000 --- a/src/app/(web)/transcribe/layout.tsx +++ /dev/null @@ -1,16 +0,0 @@ -export const metadata = { - title: 'Next.js', - description: 'Generated by Next.js', -} - -export default function RootLayout({ - children, -}: { - children: React.ReactNode -}) { - return ( - - {children} - - ) -} diff --git a/src/app/api/transcribe/__pycache__/app.cpython-39.pyc b/src/app/api/transcribe/__pycache__/app.cpython-39.pyc index 9eeb5d62d4f4c538b6b9a4ed0bbb18b8b649601a..9002252327ecc518a5bff6611661b0e51222ec2a 100644 GIT binary patch delta 19 ZcmaFM{+699k(ZZ?0SL|uZsdB*3;;961o;2} delta 19 ZcmaFM{+699k(ZZ?0SJn?H*!5@1^_X71eO2* From 51a9e7c559059d8c2112ed87d1435309491814fb Mon Sep 17 00:00:00 2001 From: Sir Blob <76974209+GamerBoss101@users.noreply.github.com> Date: Sat, 25 Jan 2025 11:51:11 -0500 Subject: [PATCH 3/4] UI Update --- src/app/(panels)/suite/patient/chat/page.tsx | 10 ++++++++++ src/app/(web)/transcribe/page.tsx | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/app/(panels)/suite/patient/chat/page.tsx diff --git a/src/app/(panels)/suite/patient/chat/page.tsx b/src/app/(panels)/suite/patient/chat/page.tsx new file mode 100644 index 0000000..f361192 --- /dev/null +++ b/src/app/(panels)/suite/patient/chat/page.tsx @@ -0,0 +1,10 @@ +"use client" + +export default function Chat() { + return ( +
+ +
+ ) +} + diff --git a/src/app/(web)/transcribe/page.tsx b/src/app/(web)/transcribe/page.tsx index 76fe1e9..0d62f1f 100644 --- a/src/app/(web)/transcribe/page.tsx +++ b/src/app/(web)/transcribe/page.tsx @@ -37,8 +37,8 @@ const AudioTranscriber: React.FC = () => { }; return ( -
-

Audio Transcription

+
+

Audio Transcription:

- {transcription && ( -
-

Transcription:

-

{transcription}

-
- )} -
- ); + // Start recording audio + const startRecording = async () => { + try { + const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); + mediaRecorderRef.current = new MediaRecorder(stream); + + audioChunksRef.current = []; // Reset audio chunks + mediaRecorderRef.current.ondataavailable = (event) => { + if (event.data.size > 0) { + audioChunksRef.current.push(event.data); + } + }; + + mediaRecorderRef.current.onstop = async () => { + const audioBlob = new Blob(audioChunksRef.current, { type: "audio/mp3" }); + const audioFile = new File([audioBlob], "recording.mp3", { type: "audio/mp3" }); + setFile(audioFile); // Save the recorded file + + // Transcribe the recorded audio + setTranscription("Transcribing the recorded audio..."); + await handleTranscription(audioFile); + }; + + mediaRecorderRef.current.start(); + setRecording(true); + } catch (error) { + console.error("Error starting recording:", error); + alert("Failed to start recording. Please check microphone permissions."); + } + }; + + // Stop recording audio + const stopRecording = () => { + if (mediaRecorderRef.current) { + mediaRecorderRef.current.stop(); + setRecording(false); + } + }; + + return ( +
+

Audio Transcription

+
+

Upload or Record Audio

+ {/* File Upload */} + + +
+ + {/* Recording Controls */} +
+

Record Audio

+ {!recording ? ( + + ) : ( + + )} +
+ + {/* Transcription Result */} +
+

Transcription:

+ {loading ? ( +

Processing transcription...

+ ) : transcription ? ( +

{transcription}

+ ) : ( +

No transcription available yet.

+ )} +
+
+ ); }; export default AudioTranscriber;