Hello world!
There are plenty of ways that we can import sound file (.wav) in grasshopper for design application. Different plugins are available on the market, such as ghowl or firefly. But today, we want to step further. Not only we want to visualize the data, but we also wish to analyze the sound file. It is appreciated if we can dig into the sound features and apply the characteristic in the geometry design.
Today, I want to show you a quick tutorial on how to visualize and analyze the frequency of your sound file.
step 00 required software
- python 3.x installed
- GH Cpython installed (https://www.food4rhino.com/app/ghcpython)
step 01. Import WAV file
The logic behind the script is pretty straight forward. We assign the directory of the sound file and transfer the audio into the frequency spectrom. For more information from the audio wave to frequency, you might need to understand the concept of Fourier Transform. The python code you may refer to
import librosa as lb import numpy as np #variable audio_file= _input a, sr = lb.load(audio_file, sr = int(s_frequency)) time = np.arange(0, len(a))/sr #stft transfer X = lb.stft(a) Xdb = lb.amplitude_to_db(abs(X)) t = lb.core.get_duration(a, sr = int(s_frequency)) #output stft = list(Xdb.flatten()) stft_frame = X.shape[1] time_duration = round(t,3)
Step 02-1. identify the major frequency in time
after we transfer the audio into frequency spectrom, we will get a 2d array. The shape of the array is (1+n_fft/2, frame), which you can identify the loudness frequency in the each time frame. By this method we can easily draw the line chart to reveal the major frequency through time.
step02-2. setup the threshold of the frequency
Since we assign the sampling frequency by range from 0 to 22050 Hz in the beginning, we might get plenty of redundant samples. However, it depends on what kind of sound that you are focusing on. In this case, I am more interested in the human voice; therefore, I set up the threshold of the frequency in 3000 Hz.
Step 03. frequency visualization
You may already use the data for design aftre step 02. However, we might consider to visualize the result for understanding the sound feature better.
To visualize the infromation, we simply take the value transform into the x,y coordinate system.
This is how you import sound file in grasshopper and use the sound feature for design purpose.
If you are interested in the post and want to know more or you want to have the original script. Feel free to email me.
Thanks for reading.