Created
March 28, 2020 01:54
-
-
Save ashwinkalyan/fce47a3e2b6e7cc52eef903171f35ed8 to your computer and use it in GitHub Desktop.
Stick man dances randomly to your favorite song (.wav)
This file contains hidden or 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
import numpy as np | |
import librosa | |
import time | |
import os | |
import pygame | |
steps =[ | |
""" | |
o | |
\ / | |
| | |
/ \\ | |
""", | |
""" | |
o | |
\ | |
|\\ | |
/ \\ | |
""", | |
""" | |
o | |
/ | |
/| | |
/ \\ | |
""", | |
""" | |
o | |
/ | |
/| | |
\\ \\ | |
""", | |
""" | |
o | |
/ | |
/| | |
/ / | |
""", | |
""" | |
o | |
\\ _ | |
| | |
/ \\ | |
""" | |
] | |
# audio_path = "beats.wav" | |
audio_path = "corona.wav" | |
y, sr = librosa.core.load(audio_path) | |
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr) | |
beat_times = librosa.frames_to_time(beat_frames, sr=sr) | |
dance_moves = np.random.choice(steps, len(beat_times)) | |
i = 0 | |
pygame.mixer.init() | |
pygame.mixer.music.load(audio_path) | |
pygame.mixer.music.play() | |
t1 = time.time() | |
while True: | |
try: | |
if time.time() - t1 >= beat_times[i]: | |
os.system('clear') | |
print(dance_moves[i]) | |
i+=1 | |
except: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment