auditok.core.load

auditok.core.load(input, skip=0, max_read=None, **kwargs)[source]

Load audio data from a source and return it as an AudioRegion.

Parameters:
  • input (None, str, bytes, AudioSource) – source to read audio data from. If str, it should be a path to a valid audio file. If bytes, it is used as raw audio data. If it is “-“, raw data will be read from stdin. If None, read audio data from the microphone using PyAudio. If of type bytes or is a path to a raw audio file then sampling_rate, sample_width and channels parameters (or their alias) are required. If it’s an AudioSource object it’s used directly to read data.
  • skip (float, default: 0) – amount, in seconds, of audio data to skip from source. If read from a microphone, skip must be 0, otherwise a ValueError is raised.
  • max_read (float, default: None) – amount, in seconds, of audio data to read from source. If read from microphone, max_read should not be None, otherwise a ValueError is raised.
  • fmt (audio_format,) – type of audio data (e.g., wav, ogg, flac, raw, etc.). This will only be used if input is a string path to an audio file. If not given, audio type will be guessed from file name extension or from file header.
  • sr (sampling_rate,) – sampling rate of audio data. Required if input is a raw audio file, a bytes object or None (i.e., read from microphone).
  • sw (sample_width,) – number of bytes used to encode one audio sample, typically 1, 2 or 4. Required for raw data, see sampling_rate.
  • ch (channels,) – number of channels of audio data. Required for raw data, see sampling_rate.
  • large_file (bool, default: False) – If True, AND if input is a path to a wav of a raw audio file (and only these two formats) then audio file is not fully loaded to memory in order to create the region (but the portion of data needed to create the region is of course loaded to memory). Set to True if max_read is significantly smaller then the size of a large audio file that shouldn’t be entirely loaded to memory.
Returns:

region

Return type:

AudioRegion

Raises:

ValueError – raised if input is None (i.e., read data from microphone) and skip != 0 or input is None max_read is None (meaning that when reading from the microphone, no data should be skipped, and maximum amount of data to read should be explicitly provided).