python-soundfile
python-soundfile copied to clipboard
read() RAW files doesn't update frame count for dynamic .raw file
Hello, I've a .raw file that gets updated every 'x' ms, and my goal is to read it in a realtime manner. However, once I instantiate an sf_file instance, the frame count doesn't get updated till I re-do instantiation and do a seek(). Is there a way around this? Apologies if this is not the right forum.
Thank you.
pos = sf_file.tell()
num_frames = 0
while (num_frames < self._frames_per_buffer):
data = sf_file.read(
frames=frames_per_buffer, always_2d=always_2d)
# check number of frames
num_frames = data.shape[0]
# wait for data to be available
if (num_frames < frames_per_buffer):
time.sleep(frame_duration_s)
# I wish following statement wasn't needed since we are reading from a file that's been updated
sf_file = sf.SoundFile(
self._filename, channels=self._channels, subtype=self._subtype, samplerate=self._samplerate)
sf_file.seek(pos)
This behavior is entirely up to libsndfile, I'm afraid. But since it's a raw file, you can probably read the file contents trivially with e.g. Numpy, and forego soundfile entirely.
Thank you @bastibe, will let you know if I find something.