Created
September 3, 2022 02:47
-
-
Save victormurcia/f23da41fc5fadca6d8b0260ef895dc5c to your computer and use it in GitHub Desktop.
Numpy to song with octaves and random pixel choice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
song = np.array([]) | |
octaves = np.array([1/2,1,2]) | |
sr = 22050 # sample rate | |
T = 0.1 # 0.1 second duration | |
t = np.linspace(0, T, int(T*sr), endpoint=False) # time variable | |
#Make a song with numpy array :] | |
#nPixels = int(len(frequencies))#All pixels in image | |
nPixels = 60 | |
for i in range(nPixels): | |
octave = random.choice(octaves) | |
val = octave * random.choice(frequencies) | |
note = 0.5*np.sin(2*np.pi*val*t) | |
song = np.concatenate([song, note]) | |
ipd.Audio(song, rate=sr) # load a NumPy array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment