maui.visualizations.spectrogram_plot¶
- maui.visualizations.spectrogram_plot(file_path, mode=None, window='hann', nperseg=1024, noverlap=None, verbose=False, fig_size=None, show_plot=True)[source]¶
Create a spectrogram plot from an audio file.
This function loads an audio file, computes its spectrogram, and generates a heatmap plot to visualize the frequency content over time.
- Parameters:
- file_pathstr
The path to the audio file.
- modestr, optional
The spectrogram mode (‘psd’, ‘mean’, ‘complex’). Default is None.
- windowstr, optional
The window function to be used for the spectrogram calculation. Default is ‘hann’.
- npersegint, optional
The number of data points used in each block for the FFT. Default is 1024.
- noverlapint, optional
The number of points of overlap between blocks. Default is None.
- verbosebool, optional
Whether to display verbose information during computation. Default is False.
- fig_sizedict, optional
A dictionary specifying the height and width of the plot. Default is None.
- show_plotbool, optional
Whether to display the plot. Default is True.
- Returns:
- plotly.graph_objs._figure.Figure
A Plotly Figure object representing the spectrogram plot.
- Raises:
- AssertionError
If the arguments are not correctly specified.
- Exception
If there are errors in the file loading or spectrogram computation.
Notes
The ‘mode’ parameter specifies the type of spectrogram to be computed: Power Spectral Density (‘psd’), Amplitude Spectrogram (‘amplitude’), or Complex Spectrogram (‘complex’).
‘fig_size’ should be a dictionary with ‘height’ and ‘width’ keys.
Examples
>>> from maui import samples, visualizations >>> df = samples.get_leec_audio_sample() >>> file_path = df.at[df.index[1],'file_path'] >>> mode = 'psd' >>> fig = visualizations.spectrogram_plot(file_path, mode=mode)