auditok.io.to_file

auditok.io.to_file(data, file, audio_format=None, **kwargs)[source]

Writes audio data to file. If audio_format is None, output audio format will be guessed from extension. If audio_format is None and file comes without an extension then audio data will be written as a raw audio file.

Parameters:
  • data (bytes-like) – audio data to be written. Can be a bytes, bytearray, memoryview, array or numpy.ndarray object.
  • file (str) – path to output audio file.
  • audio_format (str) – audio format used to save data (e.g. raw, webm, wav, ogg)
  • kwargs (dict) –

    If an audio format other than raw is used, the following keyword arguments are required:

    • sampling_rate, sr: int, sampling rate of audio data.
    • sample_width, sw: int, size in bytes of one audio sample.
    • channels, ch: int, number of channels of audio data.
Raises:
  • AudioParameterError if output format is different than raw and one or more
  • audio parameters are missing. AudioIOError if audio data cannot be written
  • in the desired format.