-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_beats.py
46 lines (35 loc) · 1.06 KB
/
test_beats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python3
"""The goal is just to play a sound for each beat that
is given by a text file. Both (music and beats) are playing
at the same time."""
import time
import pygame
from pygame.locals import *
import sys
def import_beats(beats_file):
tempo = []
with open(beats_file) as beats:
for beat in beats:
#lol = round(int(beat.split())[0])
tic = round(float((beat.split())[0]), 5)
tempo.append(tic)
return tempo
#Initialisation
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
#pygame.init()
son = pygame.mixer.Sound("musique/colouring.wav")
sonWood = pygame.mixer.Sound("musique/wood.wav")
beats_file = "musique/colouringBeats.txt"
tempo = import_beats(beats_file)
print(tempo)
error1 = time.clock()
son.play()
error2 = time.clock()
start_time = time.clock() + (error2- error1)
while 1:
current_time = round((time.clock() - start_time), 5)
#print(current_time, end = "")
#sys.stdout.write('\r')
if current_time in tempo:
sonWood.play()
print(current_time)