auditok.io.to_file
- auditok.io.to_file(data, filename, audio_format=None, **kwargs)[source]
Write audio data to a file.
This function writes audio data to a file in the specified format. If audio_format is None, the output format will be inferred from the file extension. If audio_format is None and filename has no extension, the data will be saved as a raw audio file.
- Parameters:
data (bytes-like) – The audio data to be written. Accepts bytes, bytearray, memoryview, array, or numpy.ndarray objects.
filename (str or Path) – The path to the output audio file.
audio_format (str, optional) – The audio format to use for saving the data (e.g., raw, webm, wav, ogg).
kwargs (dict, optional) –
Additional parameters required for non-raw audio formats:
sampling_rate, sr : int, the sampling rate of the audio data.
sample_width, sw : int, the size in bytes of one audio sample.
channels, ch : int, the number of audio channels.
- Raises:
AudioParameterError – Raised if the output format is not raw and one or more required audio parameters are missing.
AudioIOError – Raised if the audio data cannot be written in the specified format.