I want to represent an audio file in an image with a maximum size of 180×180 pixels.
I want to generate this image so that it somehow gives a representation of the audio file, think of it like SoundCloud's waveform (amplitude graph)?.
![Screenshot of Soundcloud's player](https://i.stack.imgur.com/kVX9b.png)
I wonder if any of you have something for this. I have been searching around for a bit, mainly "audio visualization" and "audio thumbnailing", but I have not found anything useful.
I first posted this to ux.stackexchange.com, this is my attempt to reach any programmers working on this.
You could also break up the audio into a chunks and measure the RMS (a measure of loudness). let's say you want an image that is 180 pixels wide.
I'll use pydub, a light-weight wrapper I wrote around the std lib wave
modeule:
from pydub import AudioSegment# first I'll open the audio file
sound = AudioSegment.from_mp3("some_song.mp3")# break the sound 180 even chunks (or however
# many pixels wide the image should be)
chunk_length = len(sound) / 180loudness_of_chunks = []
for i in range(180):start = i * chunk_lengthend = chunk_start + chunk_lengthchunk = sound[start:end]loudness_of_chunks.append(chunk.rms)
the for loop can be represented as the following list comprehension, I just wanted it to be clear:
loudness_of_chunks = [sound[ i*chunk_length : (i+1)*chunk_length ].rmsfor i in range(180)]
Now the only think left to do is scale the RMS down to a 0 - 180 scale (since you want the image to be 180px tall)
max_rms = max(loudness_of_chunks)scaled_loudness = [ (loudness / max_rms) * 180 for loudness in loudness_of_chunks]
I'll leave the drawing of the actual pixels to you, I'm not very experienced with PIL or ImageMagik :/