Good evening
I am a student and I have a computer project in python. The goal is to create music from a given score. So I tried to make the code below but I have a problem in my "créer_harmonique" function, the error message indicates that there is a tuple in the cosinus but I don't see why? Plus would you know how I can read my sound file once the file is created? Thank you in advance for your answers.
I am a student and I have a computer project in python. The goal is to create music from a given score. So I tried to make the code below but I have a problem in my "créer_harmonique" function, the error message indicates that there is a tuple in the cosinus but I don't see why? Plus would you know how I can read my sound file once the file is created? Thank you in advance for your answers.
from scipy.io import wavfile as wav import numpy as np import math def fréquence_gamme(Notes): for i in range(len(Demi_ton)): frequence.append(fLa/(2**(Demi_ton[i]/12))) return(frequence) def fréquences_partition(partition): for i in range(len(partition)): if Notes[0]==partition[i]: partition[i]=frequence[0] elif Notes[1]==partition[i]: partition[i]=frequence[1] elif Notes[2]==partition[i]: partition[i]=frequence[2] elif Notes[3]==partition[i]: partition[i]=frequence[3] elif Notes[4]==partition[i]: partition[i]=frequence[4] elif Notes[5]==partition[i]: partition[i]=frequence[5] elif Notes[6]==partition[i]: partition[i]=frequence[6] mon_son.append(int(partition[i])) return(mon_son) def creer_harmonique(fLa,mon_son,freq_echant): #'Génére un signal sinusoidal.' echantillons=[] A=32767 for i in range(len(mon_son)): duree_signal=1 n_échant=int(duree_signal*freq_echant) for j in range(n_échant): t=int(i/freq_echant) # t=durée entre deux echantillons a=2*3*mon_son[i]*t v = A * math.cos(a) echantillons.append(v) return(echantillons) fLa=440 freq_echant=44100 Notes=['Si','Do','Re','Mi','Fa','Sol','La'] Demi_ton=[10,9,7,5,4,2,0] mon_son=[] frequence=[] partition=['Do','Mi','Sol','Do','Mi','Sol','Do','Mi','Do','Mi','Sol','Do','Mi','Sol','Do','Mi','Do','Re','La','Re','Fa','La','Re','Fa','Do','Re','La','Re','Fa','La','Re','Fa','Re','Si','Re','Si','Do'] h = creer_harmonique(fLa,partition,freq_echant) wav.write("mon_son_a_moi",44100,np.array(h,np.int16))
Larz60+ write Feb-04-2021, 02:53 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.