generate spectrograms for music sources and store it in context

This commit is contained in:
Joel Mathew Thomas
2025-03-18 20:58:50 +05:30
parent b622585fb9
commit 018db7ea30
2 changed files with 26 additions and 3 deletions
+24 -1
View File
@@ -94,9 +94,32 @@ function ProcessingPage() {
if (!fileData.dir) { if (!fileData.dir) {
const fileBlob = await fileData.async("blob"); const fileBlob = await fileData.async("blob");
const fileURL = URL.createObjectURL(fileBlob); const fileURL = URL.createObjectURL(fileBlob);
fileURLs.push({ name: filename, url: fileURL });
// Get spectrograms
setProgress(95);
setStatusText("Calculating Spectrograms");
const formData = new FormData();
formData.append("file_uuid", response.file_uuid);
formData.append("file_name", filename);
const res = await axios.post<{
Status: string;
spectrogram: string;
spec_sr: number;
}>("/api/spectrogram", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
if (res.status === 200 && res.data){
}
fileURLs.push({ name: filename, url: fileURL, spectrogram: res.data.spectrogram, spec_sr: res.data.spec_sr });
} }
} }
console.log(fileURLs)
setExtractedFiles(fileURLs); setExtractedFiles(fileURLs);
setProgress(100); setProgress(100);
}; };
+2 -2
View File
@@ -5,8 +5,8 @@ interface MediaContextType {
setMediaFile: (file: { name: string; url: string; type: string }) => void; setMediaFile: (file: { name: string; url: string; type: string }) => void;
response: { file_uuid: string; sr: number; audio_class: string, spectrogram: string, spec_sr: number }; response: { file_uuid: string; sr: number; audio_class: string, spectrogram: string, spec_sr: number };
setResponse: (response: { file_uuid: string; sr: number; audio_class: string, spectrogram: string, spec_sr: number }) => void; setResponse: (response: { file_uuid: string; sr: number; audio_class: string, spectrogram: string, spec_sr: number }) => void;
extractedFiles: { name: string; url: string }[]; extractedFiles: { name: string; url: string, spectrogram: string, spec_sr: number }[];
setExtractedFiles: (files: {name: string; url: string }[]) => void; setExtractedFiles: (files: {name: string; url: string, spectrogram: string, spec_sr: number}[]) => void;
downloadedFileURL: string; downloadedFileURL: string;
setDownloadedFileURL: ( file: string) => void; setDownloadedFileURL: ( file: string) => void;
} }