Reading a large .wav file

389 views
Skip to first unread message

Juliana Moron

unread,
May 12, 2016, 10:03:27 AM5/12/16
to seewave
Dear collegues,

I'm trying to read a large .wav file (35 minutes long, 1.12Gb, sample rate 96000 Hz, 24 bit) that was recorded with two channels, in order to cut it in 3 same duration files. 

The thing is, I'm not succeeding in reading it. I already tried readWave: 

Error: cannot allocate vector of size 4.5 Gb
In addition: Warning messages:
1: In matrix(sample.data, nrow = 3) :
  Reached total allocation of 8072Mb: see help(memory.size)


Error: cannot allocate vector of size 4.5 Gb
In addition: Warning messages:
1: In matrix(sample.data, nrow = 3) :
 Reached total allocation of 8072Mb: see help(memory.size)

And even installed sox... But I'm not succeeding on use it on R

require(sox) 
Loading required package: SoX
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘SoX’
sox()
Error in paste(exe, command, sep = " ") : 
  argument "command" is missing, with no default

What am I missing? Any suggestions?

Stefanie LaZerte

unread,
May 12, 2016, 1:15:41 PM5/12/16
to see...@googlegroups.com
Hi Juliana

R doesn't work well with large sound files, as you can see in your memory overload!

The problem with SoX is that it isn't a package in R, but an external command-line program which you can access through seewave. You need to install it on your computer before using it (http://sox.sourceforge.net/).

However, if you only have a few files to cut up, you may want to try Audacity (https://sourceforge.net/projects/audacity/) which is a visual open source sound editor. It can handle longer wave files much better than R. It isn't as quick as SoX but it's much easier to learn.

Good luck,

Steffi
Dr. Stefanie LaZerte
Natural Resources and Environmental Studies
University of Northern BC
stefanie...@unbc.ca
http://steffi.ca/
--
You received this message because you are subscribed to the Google Groups "seewave" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seewave+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Juliana Moron

unread,
May 13, 2016, 7:38:37 AM5/13/16
to seewave
Dear Steffi,

Thank you so much for your help and response!! 
I'm doing a work for a discipline, and I proposed to cut large audio files using R... At first I thought that I could solve the problem increasing the memory limit, but it didn't help.
I'll try to use sox again.

Stefanie LaZerte

unread,
May 13, 2016, 12:22:20 PM5/13/16
to see...@googlegroups.com
Hi Juliana,

You can definitely cut files in sox, you just need to install it and then pass the command through the sox() function. I think you'll want to use the trim option (see http://sox.sourceforge.net/sox.html for the manual) you can also see ?sox in R to see how you can use sox from R.

Sox is a bit tricky to figure out at first, but it will definitely let you cut your waves from R.


Good luck,

Steffi

Dr. Stefanie LaZerte
Natural Resources and Environmental Studies
University of Northern BC
stefanie...@unbc.ca
http://steffi.ca/
Message has been deleted
Message has been deleted
Message has been deleted

Juliana Moron

unread,
May 15, 2016, 8:27:39 AM5/15/16
to seewave
Hi Steffi,

The problem with sox is that the command through the sox() function is not working properly on R... I already installed sox on my notebook, required seewave and then I try the sox command on R. 
Am I missing any step? 

sox("C:/Users/Juliana/Documents/RUSP/trabalhofinal/separar\\inteiro34m.wav")
Warning message:
running command 'c:\sox-14-4-0\sox.exe C:/Users/Juliana/Documents/RUSP/trabalhofinal/separar\inteiro34m.wav' had status 127 

Stefanie LaZerte

unread,
May 16, 2016, 1:03:00 PM5/16/16
to see...@googlegroups.com
Hi Juliana,

I think the problem you have is that you're opening a file with SoX, but are not telling SoX what to do with that file. In a simple case, Sox takes commands in the following format:

input output effect

For example, if you wanted to trim the file you should something like this (I've shortened your file paths for clarity):

library(seewave)
sox("inteiro34m.wav inteiro34m_clip.wav trim 0.25 0.75")

Where inteiro34m.wav is the input file, inteiro34m_clip.wav is the new output file and trim 0.25, 0.75 is the effect you want to apply (you can string multiple effects together).

Or try:

sox("inteiro34m.wav", exe = "play")

If this still produces an error, try walking yourself through the examples in ?sox. They should work and if they don't, we'll have a better idea of where your problems are.

Good luck!


Steffi

Dr. Stefanie LaZerte
Natural Resources and Environmental Studies
University of Northern BC
stefanie...@unbc.ca
http://steffi.ca/

Juliana Moron

unread,
May 16, 2016, 5:23:58 PM5/16/16
to seewave
Thank you so much Steffi!!!

It worked!! =D

Stefanie LaZerte

unread,
May 16, 2016, 5:37:24 PM5/16/16
to see...@googlegroups.com
Great! I'm glad to hear it :)


Steffi
Dr. Stefanie LaZerte
Natural Resources and Environmental Studies
University of Northern BC
stefanie...@unbc.ca
http://steffi.ca/

Simon Linke

unread,
Jan 23, 2018, 1:22:18 AM1/23/18
to seewave
Hi Steffi! 

I am grappling with the same error but can't figure it out

When I manually call it from the console it works:
C:\>c:\sox-14-4-0\sox.exe X:\manufilt.wav X:\turbofilt.wav sinc 3k

When I run it from R I get error 322
sox("X:\\manufilt.wav X:\\turbofilt.wav sinc 3k")
Warning message:
running command 'c:\sox-14-4-0\sox.exe X:\manufilt.wav X:\turbofilt.wav sinc 3k' had status 322 

It's strange, because it seems to resolve to exactly the same command that I can manually run!
Simon

Simon Linke

unread,
Jan 23, 2018, 2:40:57 AM1/23/18
to seewave
Update!

I started R with admin rights and now it gives me 'status 2'

sox("X:\\manufilt.wav X:\\turbofilt.wav sinc 3k")
Warning message:
running command 'c:\sox-14-4-0\sox.exe X:\manufilt.wav X:\turbofilt.wav sinc 3k' had status 2

Simon Linke

unread,
Jan 23, 2018, 7:45:27 PM1/23/18
to seewave
Riddle solved, X:\\ was actually a mountpoint of a folder on a physical drive - I often use that for current projects to avoid long paths.

if I give it the full path C:\\Work\\BioRcoustic\\Flows\\Origfiles\\ it works - somehow R doesn't find drives that are mounted as a drive in Windows!
Simon
Reply all
Reply to author
Forward
0 new messages