Robot Localization
Audio.Audio Class Reference

This class can be used to play a .wav file of your choice on a speaker of your choice and record simultaneously the response from 1 or more microphones. More...

Public Member Functions

def get_bytes_width (self, wf_out)
 Returns wavfile byte width from its datatype.
 
def play_and_record (self)
 Plays input file and records output channels. More...
 
def play_and_record_long (self)
 Plays input file and records output channels, recording longer than input file is. More...
 
def save_wav_files (self, frames)
 Saves frames in audio files. More...
 
def get_device_index (self, p)
 Updates the audio device id to be used based on user input. More...
 

Detailed Description

This class can be used to play a .wav file of your choice on a speaker of your choice and record simultaneously the response from 1 or more microphones.

The source and all microphones must be connected to a soundcard which is connected to your computer. (Or use your computer as a soundcard directly)

For each microphone channel, a output .wav-file is created.

Members:

input_file = path to .wav file to be played (sine sweep or other)

output_file = path to new file where data results are stored (with or without .wav ending)

[channels] = number of channels to be recorded (1 by default) the channels will be recorded in ascending order from 0 to n_channels-1 all channels will be saved in separate files (output_file0,1,2,...)

[index] = index of audio device to use (3 by default)

[rate] = sampling frequency in Hz (44100 by default)

[chunk] = chunk size (frames per buffer, 1024 by default)

[format_au] = format of output, in pyaudio.pa... notation (default: pyaudio.paInt16)

[format_np] = format of output, in numpy.... notation (default: np.int16)

Member Function Documentation

def Audio.Audio.get_device_index (   self,
  p 
)

Updates the audio device id to be used based on user input.

Parameters: the audio-manager created with pyaudio

Returns: Nothing

def Audio.Audio.play_and_record (   self)

Plays input file and records output channels.

Same as play_and_record_long() but recording time is only as long as inputfile.

def Audio.Audio.play_and_record_long (   self)

Plays input file and records output channels, recording longer than input file is.

Returns:

frames, a list with #BUFFER elements (#BUFFER ~= Time of input_file * rate / chunk), each element is one frame with number of elements chunk*channels. The samples for different channels are stored in alternating order. (for channels x and o, one frame would be [xoxo ... xo])

if self.channels=1, each element of frames is one long string.

if self.channels>1, each element of frames is a list of format format_np.

def Audio.Audio.save_wav_files (   self,
  frames 
)

Saves frames in audio files.

Parameters:

frames, a list of #BUFFER elements, each element is one frame. (see output of play_and_record() for more details)

Returns: 1 if succeeded


The documentation for this class was generated from the following file: