import sounddevice as sd # conda install sounddevice # conda install PortAudio import numpy as np # conda install numpy import matplotlib.pyplot as plt # conda install matplotlib from scipy.fft import fft, fftfreq pi=np.pi fs=10000 #sample rate t_max=1 # sound duration time = np.arange(0, t_max, 1/fs) print(len(time)) freq=int(input('Frequence :')) sel=int(input('scie (1) ou carré (2) :')) nb=int(input('Nb de sinusoïdes :')) sound=np.zeros(len(time)) for n in range(1,nb+1,1): if sel==2 : n_impair=2*n-1 print(n_impair*freq) sound=sound+np.sin(n_impair*2*pi*freq*time)/n_impair #signal carré if sel==1 : sound=sound+((-1)**n)*np.sin(n*2*pi*freq*time)/n #signal dent de scie sd.play(sound,fs) sd.wait() # Wait until the sound finishes playing plt.figure(1) plt.plot(time,sound) #plt.xlim(0,0.1) N=len(sound) dt=1/fs timeft=fftfreq(N,dt)[:N//2] soundft=fft(sound) plt.figure(2) plt.plot(timeft,2.0/N * np.abs(soundft[0:N//2])) #if sel==1: # plt.xlim(0,11*freq) #if sel==2: # plt.xlim(0,2*nb*freq) plt.show()