preview spectrograms for music

This commit is contained in:
Joel Mathew Thomas
2025-03-18 21:06:40 +05:30
parent 018db7ea30
commit 9139ddce53
+16 -9
View File
@@ -18,6 +18,8 @@ import {
} from '@mui/icons-material'; } from '@mui/icons-material';
import StepperComponent from '../components/StepperComponent'; import StepperComponent from '../components/StepperComponent';
import { useMediaContext } from '../contexts/MediaContext'; import { useMediaContext } from '../contexts/MediaContext';
// @ts-ignore
import SpectrogramPlayer from "react-audio-spectrogram-player"
function ResultsPage() { function ResultsPage() {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -25,7 +27,6 @@ function ResultsPage() {
console.log("Extracted files are", extractedFiles); console.log("Extracted files are", extractedFiles);
// const [isPlaying, setIsPlaying] = useState(false); // const [isPlaying, setIsPlaying] = useState(false);
const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)];
const mediaFileRef = useRef(null);
const audioClass = response.audio_class const audioClass = response.audio_class
const isVideo = mediaFile?.type.includes('video'); const isVideo = mediaFile?.type.includes('video');
@@ -101,11 +102,14 @@ function ResultsPage() {
<Typography variant="body2" color="textSecondary" sx={{ mb: 1 }}> <Typography variant="body2" color="textSecondary" sx={{ mb: 1 }}>
{mediaFile.name} {mediaFile.name}
</Typography> </Typography>
<audio <SpectrogramPlayer
ref={mediaFileRef}
src={mediaFile.url} src={mediaFile.url}
style={{ width: '100%', borderRadius: '8px', boxShadow: '0 2px 10px rgba(0,0,0,0.2)' }} sxx={JSON.parse(response.spectrogram)}
controls SampleRate={response.spec_sr}
colormap={'magma'}
settings={true}
transparent={false}
navigator={true}
/> />
</Box> </Box>
{audioClass === "Music" ? ( {audioClass === "Music" ? (
@@ -120,11 +124,14 @@ function ResultsPage() {
<Typography variant="body2" color="textSecondary" sx={{ mb: 1 }}> <Typography variant="body2" color="textSecondary" sx={{ mb: 1 }}>
{file.name} {file.name}
</Typography> </Typography>
<audio <SpectrogramPlayer
ref={audioRefs[index]}
src={file.url} src={file.url}
style={{ width: '100%', borderRadius: '8px', boxShadow: '0 2px 10px rgba(0,0,0,0.2)' }} sxx={JSON.parse(file.spectrogram)}
controls SampleRate={file.spec_sr}
colormap={'magma'}
settings={true}
transparent={false}
navigator={true}
/> />
</Box> </Box>
))} ))}