Skip to content

WaveFile

WaveFile

WaveFile Source for .wav files

__init__(self, filename, channels=2, format=8, rate=44100) special

Initialize the Source

Parameters:

Name Type Description Default
filename str

path of the wav file

required
channels int

Number of channels of the file

2
format int

PyAudio format specification

8
rate int

The audio sampling rate

44100
Source code in multisensor_pipeline/modules/audio/wave.py
def __init__(self, filename: str, channels: int = 2, format: int = pyaudio.paInt16, rate: int = 44100):
    """
    Initialize the Source
    Args:
       filename: path of the wav file
       channels: Number of channels of the file
       format: PyAudio format specification
       rate: The audio sampling rate
    """
    super(WaveFile, self).__init__()
    self._frames = []
    self._wf = wave.open(filename, 'wb')
    self._wf.setnchannels(channels)
    self._wf.setsampwidth(pyaudio.get_sample_size(format))
    self._wf.setframerate(rate)

on_stop(self)

Stops the WaveFile source and closes the filestream

Source code in multisensor_pipeline/modules/audio/wave.py
def on_stop(self):
    """
    Stops the WaveFile source and closes the filestream
    """
    self._wf.close()

on_update(self, frame)

Sends chunks of the .wav file

Source code in multisensor_pipeline/modules/audio/wave.py
def on_update(self, frame: MSPDataFrame):
    """
    Sends chunks of the .wav file
    """
    if frame.topic.name == "audio":
        self._wf.writeframes(frame["chunk"])