Message Boards Message Boards

0
|
2446 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Looping over images directory and apply InverseSpectogram to get Audio?

Posted 1 year ago

Hello,

I am new to Mathematica and Wolfram language, I read the Fast introduction to programmers but still need help.

I am trying to loop over millions of images, Spectograms, in a directory, and apply the InveseSpectogram function to them. Then, I want to store those Audio files on my computer.

Audio[InverseSpectogram[image], SampleRate -> 8000]

Any help is highly appreciated.

POSTED BY: Adam N
2 Replies
Posted 1 year ago

Thank you, Rohit Namjoshi, for your help. It runs perfectly.

POSTED BY: Adam N

Hi Adam,

Here is one way. Create a function to perform the operation on one file

audio[file_] := 
 Export[file <> ".wav", #] &@ Audio[InverseSpectrogram[Import[file]], SampleRate -> 8000]

Test it to make sure it works as expected. Note that the output will be written to whatever Directory[] evaluates to with the same name as the input file with .wav appended. If you want a different audio format change the file extension in the audio function.

Assuming all of the input files are in a single directory, and that they are .png

SetDirectory["/path/to/directory"];
files = FileNames["*.png"]

audio /@ files

If you have millions of files it is going to take a while. Use ParallelMap to speed it up.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract