From 7222a8198eb5a5adecc4f29c271b2a6cbee0ac19 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:59:57 +0530 Subject: [PATCH] add preview for noisereduced file --- client/src/Pages/ProcessingPage.tsx | 32 ++++++++++++++++++++++++---- client/src/Pages/ResultsPage.tsx | 7 ++++-- client/src/contexts/MediaContext.tsx | 6 ++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 797b6a8..df2e7c8 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -8,7 +8,7 @@ import JSZip from "jszip"; function ProcessingPage() { const navigate = useNavigate(); - const { mediaFile, response, setExtractedFiles } = useMediaContext(); + const { mediaFile, response, setExtractedFiles, setDownloadedFileURL } = useMediaContext(); const [progress, setProgress] = useState(0); const [statusText, setStatusText] = useState("Analyzing media..."); @@ -40,7 +40,7 @@ function ProcessingPage() { } }; - const fetchDownload = async () => { + const fetchZipDownload = async () => { try { setStatusText("Fetching Results..."); @@ -58,6 +58,30 @@ function ProcessingPage() { console.error("Error fetching download:", error); } }; + + const fetchDownload = async () => { + try { + setStatusText("Fetching Results..."); + + const res = await axios.get(`/api/download?file_uuid=${response.file_uuid}`, { + responseType: "blob", + }); + + if (res.status === 200) { + console.log("Download successful"); + const blob = new Blob([res.data], { type: "audio/wav" }); + const fileURL = URL.createObjectURL(blob); + + setDownloadedFileURL( fileURL ); + setProgress(100); + + } else { + console.log("Failed to download the file"); + } + } catch (error) { + console.error("Error fetching download:", error); + } + }; const handleDownload = async (downloadData: Blob) => { @@ -89,10 +113,10 @@ function ProcessingPage() { processStep("/api/trim", () => { if (response.audio_class === "Music") { processStep("/api/resample", () => { - processStep("/api/separate", () => fetchDownload(), 90, "Separating music into vocals, bass, drums and other..."); + processStep("/api/separate", () => fetchZipDownload(), 90, "Separating music into vocals, bass, drums and other..."); }, 75, "Resampling audio to 44100Hz...", { sr: "44100" }); } else { - processStep("/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio..."); + processStep("/api/noisereduce", () => fetchDownload(), 90, "Reducing background noise from the audio..."); } }, 50, "Trimming silent parts from the audio..."); }, 25, "Normalizing audio frequency..."); diff --git a/client/src/Pages/ResultsPage.tsx b/client/src/Pages/ResultsPage.tsx index b4b9c70..1c0e91d 100644 --- a/client/src/Pages/ResultsPage.tsx +++ b/client/src/Pages/ResultsPage.tsx @@ -21,7 +21,7 @@ import { useMediaContext } from '../contexts/MediaContext'; function ResultsPage() { const navigate = useNavigate(); - const { mediaFile, response, extractedFiles } = useMediaContext(); + const { mediaFile, response, extractedFiles, downloadedFileURL } = useMediaContext(); console.log("Extracted files are", extractedFiles); // const [isPlaying, setIsPlaying] = useState(false); const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; @@ -104,9 +104,12 @@ function ResultsPage() { )) ) : ( + + {mediaFile?.name} +