Batch processing of spectrograms on OSX

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Batch processing of spectrograms on OSX

Michael Karr
Hello,

I'm new to scripting and I have a large collection of audio files (around 5000 samples) that I want to produce a spectrogram of.  So if I want to apply the command:
sox $1.wav -n spectrogram -m -o $1.png,
to all the files in my folder, what would be the proper syntax?

Cheers, Michael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing of spectrograms on OSX

hendrikus godvliet
Michael

mkdir spectrogram
for f in *.wav  ;do sox "$f" -n spectrogram -o  spectrogram/"$f.png"  ;done

And  with:
display "filename.png" 
will show you the spetrogram image

ore all together:
cd spectrogram
for f in *.png  ;do display "$f"   ;done

with "alt - f4" you close the image an the nex image will show up. 


Hendrikus



On Sat, Jul 21, 2012 at 4:05 AM, Michael Karr <[hidden email]> wrote:
Hello,

I'm new to scripting and I have a large collection of audio files (around 5000 samples) that I want to produce a spectrogram of.  So if I want to apply the command:
sox $1.wav -n spectrogram -m -o $1.png,
to all the files in my folder, what would be the proper syntax?

Cheers, Michael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing of spectrograms on OSX

Pascal Giard
On Sat, Jul 21, 2012 at 12:17 AM, Hendrikus Godvliet
<[hidden email]> wrote:

> Michael
>
> mkdir spectrogram
> for f in *.wav  ;do sox "$f" -n spectrogram -o  spectrogram/"$f.png"  ;done
>
> And  with:
> display "filename.png"
> will show you the spetrogram image
>
> ore all together:
> cd spectrogram
> for f in *.png  ;do display "$f"   ;done
>
> with "alt - f4" you close the image an the nex image will show up.
>
>
> Hendrikus
>
>
>
> On Sat, Jul 21, 2012 at 4:05 AM, Michael Karr <[hidden email]>
> wrote:
>>
>> Hello,
>>
>> I'm new to scripting and I have a large collection of audio files (around
>> 5000 samples) that I want to produce a spectrogram of.  So if I want to
>> apply the command:
>> sox $1.wav -n spectrogram -m -o $1.png,
>> to all the files in my folder, what would be the proper syntax?
>>
>> Cheers, Michael

Almost there.
To get exactly what he asked for, I'd go with:

for i in *.wav; do sox $i -n spectrogram -m -o ${i%%.wav}.png; done

This assumes that the shell is either bash or dash.

Cheers,

-Pascal
--
Homepage (http://organact.mine.nu)
Debian GNU/Linux (http://www.debian.org)
COMunité/LACIME: École de technologie supérieure (http://www.comunite.ca)
Integrated Microsystems Laboratory: McGill (http://www.iml.ece.mcgill.ca)

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing of spectrograms on OSX

hendrikus godvliet
Pascal

<To get exactly what he asked for, I'd go with:
Exactly - I agree.


Hendrikus


On Sat, Jul 21, 2012 at 2:06 PM, Pascal Giard <[hidden email]> wrote:
On Sat, Jul 21, 2012 at 12:17 AM, Hendrikus Godvliet
<[hidden email]> wrote:
> Michael
>
> mkdir spectrogram
> for f in *.wav  ;do sox "$f" -n spectrogram -o  spectrogram/"$f.png"  ;done
>
> And  with:
> display "filename.png"
> will show you the spetrogram image
>
> ore all together:
> cd spectrogram
> for f in *.png  ;do display "$f"   ;done
>
> with "alt - f4" you close the image an the nex image will show up.
>
>
> Hendrikus
>
>
>
> On Sat, Jul 21, 2012 at 4:05 AM, Michael Karr <[hidden email]>
> wrote:
>>
>> Hello,
>>
>> I'm new to scripting and I have a large collection of audio files (around
>> 5000 samples) that I want to produce a spectrogram of.  So if I want to
>> apply the command:
>> sox $1.wav -n spectrogram -m -o $1.png,
>> to all the files in my folder, what would be the proper syntax?
>>
>> Cheers, Michael

Almost there.
To get exactly what he asked for, I'd go with:

for i in *.wav; do sox $i -n spectrogram -m -o ${i%%.wav}.png; done

This assumes that the shell is either bash or dash.

Cheers,

-Pascal
--
Homepage (http://organact.mine.nu)
Debian GNU/Linux (http://www.debian.org)
COMunité/LACIME: École de technologie supérieure (http://www.comunite.ca)
Integrated Microsystems Laboratory: McGill (http://www.iml.ece.mcgill.ca)

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing of spectrograms on OSX

Fmiser
In reply to this post by Pascal Giard
> > Michael Karr wrote:
> >
> > I'm new to scripting...

> Pascal Giard wrote:

> To get exactly what he asked for, I'd go with:
>
> for i in *.wav; do sox $i -n spectrogram -m -o ${i%%.wav}.png;
> done
>
> This assumes that the shell is either bash or dash.

It would probably be a good idea to quote the variables.  So

for i in *.wav; do sox "$i" -n spectrogram -m -o "${i%%.wav}.png"; done

And then to explain it.

The quotes I added are so it will correctly handle things like
spaces, commas, parentheses, etc.

"for" "in", "do", and "done" are special words that indicate a
loop, in this case, a for loop.  Basically, all commands between
"do" and "done" are run on each pass of the loop as determined
by the list provided with "for".  

"for i in *.wav" creates a list of all files that end in ".wav"
in the current directory and sets the variable "i" to be the
first of those files.  Each time around the loop, "i" is set to
then next file that ends with ".wav"

In the command, the variable "i" is recalled by preceding it
with a "$", so "$i" is replaced with name of one of the wav
files, and each time around the loop it becomes a different one.

The next fancy part is "${i%%.wav}.png".  This is taking the
filename that "i" is currently set to, stripping .wav from the
end, and then adding .png.  This results in the creation of
a .png file that has exactly the same name as the .wav file -
but with a different extension.

Scripting can do a lot more, and I've glossed over some stuff,
but maybe this will be enough of an explanation you will be able
to rework the command (one liner script) to a new and different
situation next time. *smiles*

--    Philip

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing of spectrograms on OSX

Michael Karr
In reply to this post by Michael Karr
Yes, worked just fine. Thanks!

-Michael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users