# Record audio without data loss between save files | PortAudio.jl

**URL:** https://discourse.julialang.org/t/record-audio-without-data-loss-between-save-files-portaudio-jl/85007
**Category:** General Usage
**Tags:** question, audio
**Created:** [July 29, 2022, 10:50pm UTC](https://discourse.julialang.org/t/record-audio-without-data-loss-between-save-files-portaudio-jl/85007 "2022-07-29T22:50:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![frsalarcon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frsalarcon/32/38379_2.png) [@frsalarcon](https://discourse.julialang.org/u/frsalarcon)
#### Post date: [July 29, 2022, 10:50pm UTC](https://discourse.julialang.org/t/record-audio-without-data-loss-between-save-files-portaudio-jl/85007/1 "2022-07-29T22:50:12Z")

</div>

Hello everyone!  
I have a question, is there a way to record audio for example one minute through the following script using portaudio:

```julia
import LibSndFile
using PortAudio: PortAudioStream
using SampledSignals: s
using FileIO: save
using Dates
while true
        stream = PortAudioStream(1, 0)
        buf = read(stream, 60s)
        close(stream)
        save(joinpath(homedir(),"Desktop",string(now())*".ogg"),buf)
end

```

and not have data loss between the time it is saved and another recording is created? I noticed that there is a data loss of ~0.02 seconds of data. I know it’s a bit far-fetched but I need to do a spectral analysis where every piece of data counts.  
I am new with Julia so I ask for guidance. Is there any way to have a stream of data stored in a queue or buffer while those ~0.02 pass to save the file and then be able to retrieve that data? Thank you!

---

<div class="post-metadata">

### Author: ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)
#### Post date: [August 1, 2022, 10:09pm UTC](https://discourse.julialang.org/t/record-audio-without-data-loss-between-save-files-portaudio-jl/85007/2 "2022-08-01T22:09:05Z")

</div>

Can you move the stream open and close operations outside of the loop?
