add corresponding process messages
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Snackbar, Alert } from "@mui/material";
|
import { Snackbar, Alert } from "@mui/material";
|
||||||
import { Typography, Container, Paper, Box, LinearProgress } from "@mui/material";
|
import {
|
||||||
|
Typography,
|
||||||
|
Container,
|
||||||
|
Paper,
|
||||||
|
Box,
|
||||||
|
LinearProgress,
|
||||||
|
} from "@mui/material";
|
||||||
import StepperComponent from "../components/StepperComponent";
|
import StepperComponent from "../components/StepperComponent";
|
||||||
import { useMediaContext } from "../contexts/MediaContext";
|
import { useMediaContext } from "../contexts/MediaContext";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -12,27 +18,29 @@ function ProcessingPage() {
|
|||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [severity, setSeverity] = useState("info");
|
const [severity, setSeverity] = useState<
|
||||||
|
"success" | "error" | "warning" | "info"
|
||||||
|
>("info");
|
||||||
|
const [statusText, setStatusText] = useState("Analyzing media...");
|
||||||
|
|
||||||
const showToast = (msg, type) => {
|
const showToast = (
|
||||||
|
msg: string,
|
||||||
|
type: "success" | "error" | "warning" | "info"
|
||||||
|
) => {
|
||||||
setMessage(msg);
|
setMessage(msg);
|
||||||
setSeverity(type);
|
setSeverity(type);
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
const processStep = async (url, nextStep, progressValue, extraData = null) => {
|
const processStep = async (url: string, nextStep: () => void, progressValue: number, status: string, extraData = {}) => {
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file_uuid", response.file_uuid);
|
formData.append("file_uuid", response.file_uuid);
|
||||||
|
Object.entries(extraData).forEach(([key, value]) => formData.append(key, value));
|
||||||
|
|
||||||
if (extraData) {
|
setStatusText(status);
|
||||||
for (const key in extraData) {
|
|
||||||
formData.append(key, extraData[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const res = await axios.post(url, formData, {
|
const res = await axios.post(url, formData, {
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
@@ -64,19 +72,14 @@ function ProcessingPage() {
|
|||||||
processStep("http://127.0.0.1:8000/api/normalize", () => {
|
processStep("http://127.0.0.1:8000/api/normalize", () => {
|
||||||
processStep("http://127.0.0.1:8000/api/trim", () => {
|
processStep("http://127.0.0.1:8000/api/trim", () => {
|
||||||
if (response.audio_class === "Music") {
|
if (response.audio_class === "Music") {
|
||||||
processStep(
|
processStep("http://127.0.0.1:8000/api/resample", () => {
|
||||||
"http://127.0.0.1:8000/api/resample",
|
processStep("http://127.0.0.1:8000/api/separate", () => setProgress(100), 100, "Separating sources into vocals, bass, drums and other...");
|
||||||
() => {
|
}, 75, "Resampling audio to 44100Hz...", { sr: response.sr?.toString() || "44100" });
|
||||||
processStep("http://127.0.0.1:8000/api/separate", () => setProgress(100), 100);
|
|
||||||
},
|
|
||||||
75,
|
|
||||||
{ sr: response.sr?.toString() || "44100" }
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
processStep("http://127.0.0.1:8000/api/noisereduce", () => setProgress(100), 100);
|
processStep("http://127.0.0.1:8000/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio...");
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50, "Trimming silent parts from the audio...");
|
||||||
}, 25);
|
}, 25, "Normalizing audio frequency...");
|
||||||
}, [mediaFile, navigate]);
|
}, [mediaFile, navigate]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -110,13 +113,7 @@ function ProcessingPage() {
|
|||||||
|
|
||||||
<Box sx={{ mt: 6 }}>
|
<Box sx={{ mt: 6 }}>
|
||||||
<Typography variant="body1" color="textSecondary">
|
<Typography variant="body1" color="textSecondary">
|
||||||
{progress < 30
|
{statusText}
|
||||||
? "Analyzing media..."
|
|
||||||
: progress < 60
|
|
||||||
? "Applying processing..."
|
|
||||||
: progress < 90
|
|
||||||
? "Finalizing..."
|
|
||||||
: "Almost done..."}
|
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Snackbar
|
<Snackbar
|
||||||
|
|||||||
Reference in New Issue
Block a user