_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) | tensorlikeEither an audio file, or an audio tensor\ndarray with a sample rate
over_curvetensorlike | List[tensorlike] | Dict[str, tensorlike] | callableA 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_curvesrintThe sample rate, when the source does not contain a sample rate, the given
srvalue 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 specifiedsrvalue.frame_msfloatSets the spectrogram frame length to the given amount of milliseconds, default is 100.0.
n_fftintSets the
n_fftof the spectrogram, overrides theframe_msvalue, default is(sr/1000 * frame_ms).hop_msfloatSets the
hop_lengthof the spectrogram, in milliseconds.hop_lengthintSets the
hop_lengthof the spectrogram, default isn_fft/8titlestrA title to be used when saving the plot. If
embed_titleis True, thetitlevalue will be displayed as part of the plot itself. Default is “waloviz”.embed_titleboolWhen True, the
titlevalue will be displayed as part of the plot itself, default is False.heightint | strThe total height of the plot, default is “responsive”, which means the plot will stretch in height to fit.
widthint | strThe total width of the plot, default is “responsive”, which means the plot will stretch in width to fit.
aspect_ratiofloatThe ratio between the width and height, relevant only when either width, height or both are “responsive”, default is 3.5.
sizing_modestrThe 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_legendsboolWhether the legends of both audio channels over curves should be synchronized, default is False
colorbarboolWhether to display a colorbar for the spectrograms, default is False
cmapstrThe 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 givenover_curvevalue.themestr | Dict[str, Any]Sets the visual look and feel of the plot, the value provided must be a
bokehtheme, default is “dark_minimal”.max_sizeintWhen the spectrogram or one of the over curves contain many values, the plot’s performance suffers. For that reason
max_sizelimits the amount of displayed values, when the spectrogram or an over curve has more values than themax_size, it is reduced in size by skipping intermediate values, until the size is less than themax_size. Default is 10000.download_buttonboolWhether to show the html download button. Defaults to True.
freq_labelstrThe 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 givenover_curvevalue. 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_axesparameter.native_playerboolWhether the underlying native audio player should be visible. Default is False
minimalboolDoes nothing when False, when True it overrides some settings to make the player more compact and simple. Default is False.
extendedboolDoes nothing when False, when True it overrides some settings to make the player more descriptive and functional. Default is False.
Returns#
playerpn.viewable.ViewableAn interactive player, can be saved to html with
wv.save(player)
Raises#
ValueError- When both
minimal=Trueandextended=TrueORWhen no sample-rate was providedORWhen thewavtensor had more than 2 non squeezable dimensionsORWhen thethemestring value was not found in BokehORWhen there are more than 2 positionalargsORWhen the providedover_curvewas 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 themodeparameter is “colab” those two lines of code will rerun on everywv.Audiocall.Examples#
import wavloviz as wv wv.extension() wv.Audio('http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')
Parameters#
modestrSets 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) | tensorlikeThe player created by
wv.Audio, or a source forwv.Audioto create a player with.out_filestr | os.PathLike | IOThe output file path for the generated html, default is “{title}.html”
titlestrThe 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.ResourcesThe resources for the
panelsave method, default is INLINEembedboolThe embed value for the
panelsave method, default is True
Returns#
out_filestr | os.PathLike | IOThe file that the HTML player content was written into
Raises#
ValueErrorWhen called with more than 2 positional
args