Skip to content

Loading and saving using streaming #52

Description

@abhayap

Hi, I have two large WAV files that I want to load, process and save in chunks because they won't fit into my memory. I have the code below but I am getting an error when trying to use the savestreaming function.

using FileIO: load, save, loadstreaming, savestreaming
import LibSndFile

d = mktempdir()
a,b = randn(Float32,10000,4), randn(Float32,10000,4)
save(joinpath(d,"f1.wav"), a, Fs=8000)
save(joinpath(d,"f2.wav"), b, Fs=8000)

savestream = savestreaming(joinpath(d,"s1.wav"))
for wavfile in ["f1.wav", "f2.wav"]
    loadstreaming(joinpath(d,wavfile)) do audio
        while !eof(audio)
            chunk = read(audio, 100) # read 100 frames
            # process the chunk
            chunk -= .001
            write(savestream, chunk)
        end
    end
end
close(savestream)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions