maad.sound.load

maad.sound.load(filename, channel='left', detrend=True, verbose=False, display=False, savefig=None, **kwargs)[source]

Load an audio file (stereo or mono).

Currently, this function con only load WAVE files.

Parameters:
filenamestring

Name or path of the audio file

channel{‘left’, right’}, optional, default: left

In case of stereo sound select the channel that is kept

detrendboolean, optional, default is True

Subtract the DC value.

verboseboolean, optional, default is False

Print messages into the console or terminal if verbose is True

displayboolean, optional, default is False

Display the signal if True

savefigstring, optional, default is None

Root filename (with full path) is required to save the figures. Postfix is added to the root filename.

kwargs, optional. This parameter is used by plt.plot and savefig functions
  • savefilenamestr, optional, default :’_audiogram.png’

    Postfix of the figure filename

  • figsizetuple of integers, optional, default: (4,10)

    width, height in inches.

  • titlestring, optional, default‘Spectrogram’

    title of the figure

  • xlabelstring, optional, default‘Time [s]’

    label of the horizontal axis

  • ylabelstring, optional, default‘Amplitude [AU]’

    label of the vertical axis

  • cmapstring or Colormap object, optional, default is ‘gray’

    See https://matplotlib.org/examples/color/colormaps_reference.html in order to get all the existing colormaps examples: ‘hsv’, ‘hot’, ‘bone’, ‘tab20c’, ‘jet’, ‘seismic’, ‘viridis’…

  • vmin, vmaxscalar, optional, default: None

    vmin and vmax are used in conjunction with norm to normalize luminance data. Note if you pass a norm instance, your settings for vmin and vmax will be ignored. extent : list of scalars [left, right, bottom, top], optional, default: None The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.

  • dpiinteger, optional, default is 96

    Dot per inch. For printed version, choose high dpi (i.e. dpi=300) => slow For screen version, choose low dpi (i.e. dpi=96) => fast

  • formatstring, optional, default is ‘png’

    Format to save the figure

… and more, see matplotlib

Returns:
s_out1d ndarray of integer

Vector containing the audiogram

fsint

The sampling frequency in Hz of the audiogram

Examples

>>> import maad
>>> s, fs = maad.sound.load("../data/tropical_forest_morning.wav", channel='left')
>>> print("The sampling frequency of the audio file is {} Hz".format(fs))
The sampling frequency of the audio file is 48000 Hz
>>> import numpy as np
>>> tn = np.arange(0,len(s))/fs
>>> import matplotlib.pyplot as plt
>>> fig, (ax0, ax1) = plt.subplots(2,1, sharex=True, squeeze=True)
>>> ax0, _ = maad.util.plot1d(tn,s,ax=ax0, figtitle='ground level')
>>> ax0.set_ylim((-0.075,0.075))
(-0.075, 0.075)
>>> s, fs = maad.sound.load("../data/tropical_forest_morning.wav", channel='right')
>>> ax1, _ = maad.util.plot1d(tn,s,ax=ax1, figtitle='canopy level')
>>> ax1.set_ylim((-0.075,0.075))
(-0.075, 0.075)
>>> fig.tight_layout()