mlx.data.Buffer.load_audio#
- Buffer.load_audio(self: mlx.data._c.Buffer, key: str, prefix: str = '', info: bool = False, from_memory: bool = False, info_type: mlx.data._c.LoadAudioInfo = <LoadAudioInfo.All: 0>, sample_rate: int = 0, resampling_quality: str = 'sinc-fastest', info_key: str = '', output_key: str = '') mlx.data._c.Buffer#
Load an audio file.
Decodes audio from an audio file on disk or in memory. It can also load the audio info instead. If a sample rate is provided it resamples the audio to the requested rate.
If
info_typeis set toLoadAudioInfo.Allthen the result will contain the number of frames, the number of channels and the sampling rate of the audio file.It can also be set to
LoadAudioInfo.NumFrames,LoadAudioInfo.NumChannels,LoadAudioInfo.SampleRateandLoadAudioInfo.NumSecondsto load the corresponding information.The following example filters from the
Streamall audio files that are less than 10 seconds long.dset = ( dset .load_audio("audio_file", info=True, info_type=LoadAudioInfo.NumSeconds, output_key="audio_info") .sample_transform(lambda s: s if s["audio_info"] >= 10 else dict()) )
- Parameters:
key (str) – The sample key that contains the array we are operating on.
prefix (str) – The filepath prefix to use when loading the audio files.
info (bool) – If set to True load the audio file information instead of the data in
output_key, wheninfo_keyis not provided. (default: False)from_memory (bool) – If true assume the file contents are in the array instead of the file name. (default: False)
info_type (LoadAudioInfo) – If
infois True then load this type of audio metadata.sample_rate (int) – The requested sample frequency in frames per second. If it is set to 0 then no resampling is performed. (default: 0)
resampling_quality – (sinc-fastest|sinc-medium|sinc-best|zero-order-hold|linear): Chooses the audio resampling quality if resampling is performed. (default: sinc-fastest)
info_key (str) – The key to store the audio metadata in, if desired. (default: ‘’)
output_key (str) – The key to store the result in. If it is an empty string then overwrite the input. (default: ‘’)