Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading and saving using streaming #52

Open
abhayap opened this issue Feb 21, 2022 · 1 comment
Open

Loading and saving using streaming #52

abhayap opened this issue Feb 21, 2022 · 1 comment

Comments

@abhayap
Copy link

abhayap commented Feb 21, 2022

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)

@abhayap
Copy link
Author

abhayap commented Feb 21, 2022

This is the error I am getting.

Errors encountered while savestreaming FileIO.File{FileIO.DataFormat{:WAV}, String}("/var/folders/4c/__7x6ly53gb4pm7mxfvwsrk00000gn/T/jl_wRsFOg/s1.wav").
All errors:
===========================================
WAV writer error: neither savestreaming nor fileio_savestreaming is defined
  due to FileIO.SpecError(WAV, :savestreaming)
  Will try next loader.

===========================================
MethodError: no method matching savestreaming(::FileIO.File{FileIO.DataFormat{:WAV}, String})
Closest candidates are:
  savestreaming(::Union{FileIO.File{T}, FileIO.Stream{T}}, ::Any, ::Any, ::Any) where T at ~/.julia/packages/LibSndFile/kDrKU/src/loadsave.jl:36
===========================================

Fatal error:
ERROR: LoadError: WAV writer error: neither savestreaming nor fileio_savestreaming is defined
  due to FileIO.SpecError(WAV, :savestreaming)
  Will try next loader.

Stacktrace:
 [1] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:215
 [2] action
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:197 [inlined]
 [3] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:185
 [4] action
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:185 [inlined]
 [5] #savestreaming#23
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:129 [inlined]
 [6] savestreaming(::String)
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:126
 [7] top-level scope
   @ ~/dev/pie/spharrayproc/julia/src/applearrayproc.jl:175
Stacktrace:
 [1] handle_error(e::FileIO.WriterError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/error_handling.jl:61
 [2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector}}, action::String)
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/error_handling.jl:56
 [3] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:228
 [4] action
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:197 [inlined]
 [5] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:185
 [6] action
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:185 [inlined]
 [7] #savestreaming#23
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:129 [inlined]
 [8] savestreaming(::String)
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:126
 [9] top-level scope
   @ ~/dev/pie/spharrayproc/julia/src/applearrayproc.jl:175
in expression starting at /Users/aparthy/dev/pie/spharrayproc/julia/src/applearrayproc.jl:175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant