_user_functions Module#

_user_functions Module#

waloviz._user_functions.Audio(source: Union[str, PathLike, BinaryIO, ndarray, Tensor, Any, Tuple[Union[ndarray, Tensor, Any], int]], over_curve: Optional[Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any]] = None, *args: Tuple, over_curve_names: Optional[Union[str, List[str]]] = None, sr: Optional[int] = None, frame_ms: Optional[int] = None, n_fft: Optional[int] = None, hop_ms: Optional[int] = None, hop_length: Optional[int] = None, title: Optional[str] = 'waloviz', embed_title: bool = False, height: Union[int, str] = 'responsive', width: Union[int, str] = 'responsive', aspect_ratio: Optional[float] = None, sizing_mode: Optional[str] = None, sync_legends: bool = False, colorbar: bool = False, cmap: str = 'Inferno', over_curve_colors: Optional[Union[str, List[Optional[str]], Dict[str, str]]] = None, theme: Union[str, Dict[str, Any]] = 'dark_minimal', max_size: int = 10000, download_button: bool = True, freq_label: Optional[str] = 'Hz', over_curve_axes: Optional[Union[str, List[Optional[str]], List[str], Dict[str, str]]] = None, axes_limits: Optional[Dict[str, Tuple[Optional[Union[float, int]], Optional[Union[float, int]]]]] = None, native_player: bool = False, minimal: bool = False, extended: bool = False) Viewable[source]#
Create an interactive audio player with a spectrogram.

Examples#

import wavloviz as wv
wv.Audio('http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')
wav, sr = np.random.randn(8000), 8000
wv.Audio((wav, sr))
wav, sr = torchaudio.load('http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')
wv.Audio(wav, sr=sr, over_curve=dict(squared=wav**2, cubed=wav**3))

Parameters#

sourcestr | os.PathLike | IO | (tensorlike, int) | tensorlike

Either an audio file, or an audio tensor\ndarray with a sample rate

over_curvetensorlike | List[tensorlike] | Dict[str, tensorlike] | callable

A single or multiple curves to be displayed over the spectrogram

over_curve_namesstr | List[str]

A list of display names corresponding to the list given in over_curve

srint

The sample rate, when the source does not contain a sample rate, the given sr value is assumed to be the source sample rate, when this value is different than the source sample rate, the source audio is resampled to the specified sr value.

frame_msfloat

Sets the spectrogram frame length to the given amount of milliseconds, default is 100.0.

n_fftint

Sets the n_fft of the spectrogram, overrides the frame_ms value, default is (sr/1000 * frame_ms) .

hop_msfloat

Sets the hop_length of the spectrogram, in milliseconds.

hop_lengthint

Sets the hop_length of the spectrogram, default is n_fft/8

titlestr

A title to be used when saving the plot. If embed_title is True, the title value will be displayed as part of the plot itself. Default is “waloviz”.

embed_titlebool

When True, the title value will be displayed as part of the plot itself, default is False.

heightint | str

The total height of the plot, default is “responsive”, which means the plot will stretch in height to fit.

widthint | str

The total width of the plot, default is “responsive”, which means the plot will stretch in width to fit.

aspect_ratiofloat

The ratio between the width and height, relevant only when either width, height or both are “responsive”, default is 3.5.

sizing_modestr

The panel sizing_mode , can be one of seven values: “stretch_width”, “stretch_height”, “stretch_both”, “scale_width”, “scale_height”, “scale_both”, or “fixed”. Default is “scale_both”.

sync_legendsbool

Whether the legends of both audio channels over curves should be synchronized, default is False

colorbarbool

Whether to display a colorbar for the spectrograms, default is False

cmapstr

The colormap used to display the spectrogram, default is “Inferno”

over_curve_colorsstr | List[str] | Dict[str, str]

Sets the colors to display for each given over_curve , should match the size and structure of the given over_curve value.

themestr | Dict[str, Any]

Sets the visual look and feel of the plot, the value provided must be a bokeh theme, default is “dark_minimal”.

max_sizeint

When the spectrogram or one of the over curves contain many values, the plot’s performance suffers. For that reason max_size limits the amount of displayed values, when the spectrogram or an over curve has more values than the max_size , it is reduced in size by skipping intermediate values, until the size is less than the max_size . Default is 10000.

download_buttonbool

Whether to show the html download button. Defaults to True.

freq_labelstr

The label of the frequency axis (vertical), hides the label when set to None which saves space.

over_curve_axesstr | List[str] | Dict[str, str]

Sets the axis for each given over_curve , should match the size and structure of the given over_curve value. Setting the axis to “Hz” will sync the curve to the frequency axis of the spectrogram.

axes_limitsDict[str, Tuple[float, float]]

Sets default limits for the different axes, the available axes are “x” for the time dimension, “Hz” for the frequency dimension, “y” for the default over curves dimension, and any other axis provided in the over_curve_axes parameter.

native_playerbool

Whether the underlying native audio player should be visible. Default is False

minimalbool

Does nothing when False, when True it overrides some settings to make the player more compact and simple. Default is False.

extendedbool

Does nothing when False, when True it overrides some settings to make the player more descriptive and functional. Default is False.

Returns#

playerpn.viewable.Viewable

An interactive player, can be saved to html with wv.save(player)

Raises#

ValueError
When both minimal=True and extended=True
OR
When no sample-rate was provided
OR
When the wav tensor had more than 2 non squeezable dimensions
OR
When the theme string value was not found in Bokeh
OR
When there are more than 2 positional args
OR
When the provided over_curve was an integer

waloviz._user_functions.extension(mode: str = 'default') None[source]#
Initializes the notebook extensions for the current IDE.
It is the equivalent of:
hv.extension("bokeh")
pn.extension(comms="default")
When the mode parameter is “colab” those two lines of code will rerun on every wv.Audio call.

Examples#

import wavloviz as wv
wv.extension()
wv.Audio('http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')

Parameters#

modestr

Sets the mode of WaloViz, currently the only active mode is “colab”. Default is “default”


waloviz._user_functions.save(source: Union[Viewable, str, PathLike, BinaryIO, ndarray, Tensor, Any, Tuple[Union[ndarray, Tensor, Any], int]], second_arg: Optional[Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any, str, PathLike, IO]] = None, *args: Tuple, out_file: Optional[Union[str, PathLike, IO]] = None, title: Optional[str] = None, resources: Resources = Resources(mode='inline'), embed: bool = True, **kwargs: Dict[str, Any]) Union[str, PathLike, IO][source]#
Saves a player to an html file.

Example#

import wavloviz as wv
wv.save('http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')

Parameters#

sourcepn.viewable.Viewable | str | os.PathLike | IO | (tensorlike, int) | tensorlike

The player created by wv.Audio , or a source for wv.Audio to create a player with.

out_filestr | os.PathLike | IO

The output file path for the generated html, default is “{title}.html”

titlestr

The title to be used in the generated file name and the html title, if wv.Audio(title="...") was specified, then that value is used, otherwise, the default is “waloviz”.

resourcesbokeh.resources.Resources

The resources for the panel save method, default is INLINE

embedbool

The embed value for the panel save method, default is True

Returns#

out_filestr | os.PathLike | IO

The file that the HTML player content was written into

Raises#

ValueError

When called with more than 2 positional args