auditok.io — auditok 0.1.4 documentation

# auditok.io

Module for low-level audio input-output operations.

## Class summary

`AudioSource`([sampling_rate, sample_width, ...]) | Base class for audio source objects.
`Rewindable` | Base class for rewindable audio streams.
`BufferAudioSource`(data_buffer[, ...]) | An `AudioSource` that encapsulates and reads data from a memory buffer.
`WaveAudioSource`(filename) | A class for an AudioSource that reads data from a wave file.
`PyAudioSource`([sampling_rate, sample_width, ...]) | A class for an AudioSource that reads data the built-in microphone using PyAudio.
`StdinAudioSource`([sampling_rate, ...]) | A class for an `AudioSource` that reads data from standard input.
`PyAudioPlayer`([sampling_rate, sample_width, ...]) | A class for audio playback using Pyaudio

## Function summary

`from_file`(filename) | Create an AudioSource object using the audio file specified by filename.
`player_for`(audio_source) | Return a `PyAudioPlayer` that can play data from audio_source.

class `auditok.io.` `AudioSource`(sampling_rate=16000, sample_width=2, channels=1)

  Base class for audio source objects.

  Subclasses should implement methods to open/close and audio stream and read the desired amount of audio samples.

  Parameters: | sampling_rate : int Number of samples per second of audio stream. Default = 16000. sample_width : int Size in bytes of one audio sample. Possible values : 1, 2, 4. Default = 2. channels : int Number of channels of audio stream. The current version supports only mono audio streams (i.e. one channel).

  `close`()

    Close audio source

  `get_channels`()

    Return the number of channels of this audio source

  `get_sample_width`()

    Return the number of bytes used to represent one audio sample

  `get_sampling_rate`()

    Return the number of samples per second of audio stream

  `is_open`()

    Return True if audio source is open, False otherwise

  `open`()

    Open audio source

  `read`(size)

    Read and return size audio samples at most.

    Parameters: | size : int the number of samples to read.
    Returns: | Audio data as a string of length ‘N’ * ‘smaple_width’ * ‘channels’, where ‘N’ is: size if size < ‘left_samples’ ‘left_samples’ if size > ‘left_samples’

class `auditok.io.` `Rewindable`

  Base class for rewindable audio streams. Subclasses should implement methods to return to the beginning of an audio stream as well as method to move to an absolute audio position expressed in time or in number of samples.

  `get_position`()

    Return the total number of already read samples

  `get_time_position`()

    Return the total duration in seconds of already read data

  `rewind`()

    Go back to the beginning of audio stream

  `set_position`(position)

    Move to an absolute position

    Parameters: | position : int number of samples to skip from the start of the stream

  `set_time_position`(time_position)

    Move to an absolute position expressed in seconds

    Parameters: | time_position : float seconds to skip from the start of the stream

class `auditok.io.` `BufferAudioSource`(data_buffer, sampling_rate=16000, sample_width=2, channels=1)

  An `AudioSource` that encapsulates and reads data from a memory buffer. It implements methods from `Rewindable` and is therefore a navigable `AudioSource`.

  `append_data`(data_buffer)

    Append data to this audio stream

    Parameters: | data_buffer : str, basestring, Bytes a buffer with a length multiple of (sample_width * channels)

  `get_data_buffer`()

    Return all audio data as one string buffer.

  `set_data`(data_buffer)

    Set new data for this audio stream.

    Parameters: | data_buffer : str, basestring, Bytes a string buffer with a length multiple of (sample_width * channels)

class `auditok.io.` `WaveAudioSource`(filename)

  A class for an AudioSource that reads data from a wave file.

  Parameters: | filename : path to a valid wave file

class `auditok.io.` `PyAudioSource`(sampling_rate=16000, sample_width=2, channels=1, frames_per_buffer=1024)

  A class for an AudioSource that reads data the built-in microphone using PyAudio.

class `auditok.io.` `StdinAudioSource`(sampling_rate=16000, sample_width=2, channels=1)

  A class for an `AudioSource` that reads data from standard input.

class `auditok.io.` `PyAudioPlayer`(sampling_rate=16000, sample_width=2, channels=1)

  A class for audio playback using Pyaudio

`auditok.io.` `from_file`(filename)

  Create an AudioSource object using the audio file specified by filename. The appropriate AudioSource class is guessed from file’s extension.

  Parameters: | filename : path to an audio file.
  Returns: | an AudioSource object that reads data from the given file.

`auditok.io.` `player_for`(audio_source)

  Return a `PyAudioPlayer` that can play data from audio_source.

  Parameters: | audio_source : an AudioSource object.
  Returns: | PyAudioPlayer that has the same sampling rate, sample width and number of channels as audio_source.