Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 3d700eae rédigé par Antoine BRENAGET's avatar Antoine BRENAGET
Parcourir les fichiers

Update Code/SoundPlayer.py

parent d6c33c2c
Branches SoundPlayer
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -3,7 +3,7 @@ import numpy
sampleRate = 44100
# Play a sound of the given frequencies
# Save a sound of the given frequencies
# freqs : list of frequencies to be played
# dur : sound's duration
# vol : list of frequencies's volumes
......@@ -11,10 +11,14 @@ def playFreqs(freqs, dur, vol):
# Create the audio array
arr = []
for t in numpy.linspace(0., 1., sampleRate):
val = 1000 * numpy.sin(2.0 * numpy.pi * freqs[0] * t)
val = 0
for i in range(len(freqs)):
val += vol[i] * numpy.sin(2.0 * numpy.pi * freqs[i] * t)
arr.append(val)
arr = numpy.array(arr).astype(numpy.int16)
# Play sound
write("exemple.wav", sampleRate, arr)
# Save the sound
write("Sound.wav", sampleRate, arr)
playFreqs([441.43], 1000, [1000])
\ No newline at end of file
freqs = [440 * i for i in range(1, 20)]
vol = [1000 / i**2 for i in range(1, 20)]
playFreqs(freqs, 1000, vol)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter