Commit 67909f00 authored by LucasDANIELE's avatar LucasDANIELE
Browse files

Ajout d'informations descriptives

parent 7d2b6f2a
......@@ -13,8 +13,6 @@ import numpy as np
import fcts as fcts
import importlib
import frequency_estimator as f0
# importlib.reload(fcts)
# importlib.reload(f0)
#%%
################################################
......@@ -22,8 +20,8 @@ import frequency_estimator as f0
################################################
start_time = time()
bEnSec = 0*3600 + 0*60 + 0
duree = 0*3600 + 1*60 + 0
bEnSec = 2*3600 + 45*60 + 0
duree = 4*3600 + 0*60 + 0
samplerate, dataLR = wavfile.read("input/male2.wav")#On lit le fichier qui a des infos oreille gauche, oreille droite
dataL = dataLR[:,0]#On recupère que le son de l'oreille gauche
......@@ -46,25 +44,30 @@ data = dataL[b:n+b]#On recupere n echantillons depuis b soit depuis bEnSec --> S
# Support temporel signal découpé
################################################
dataCut = fcts.decouperExtraits(data, 2500, 0.1, samplerate, 20000)
dataCut = fcts.decouperExtraits(data, 2000, 0.1, samplerate, 20000, start_time)
#%%
################################################
# Support temporel uniquement cris
################################################
dataCutCris, freqArray = fcts.garderUniquementCris(samplerate,0.38,0.6,250,450,f0.freq_from_HPS, dataCut, data)
#dataCutCris, freqArray = fcts.garderUniquementCris(samplerate,0.38,0.6,250,450,0.06, f0.freq_from_HPS, dataCut, data)
dataCutCris, freqArray = fcts.garderUniquementCris(samplerate,0.35,1,250,450,0.06, f0.freq_from_HPS, dataCut, data)
for i in range(len(dataCutCris)):
fcts.aff("cri"+str(i), t, np.asarray(data[d:f]))
d=dataCutCris[i][0]
f=dataCutCris[i][1]
fcts.aff("cri"+str(i), t, np.asarray(data[d:f]))
fcts.listen("output/cri"+str(i)+".wav", samplerate, np.asarray(data[d:f]))
print("*************************")
print("* enregistrement: " + str(i))
print("*************************")
print("* f0 -> " + str(np.round(freqArray[i])))
print("* duration -> " + str((f-d)/samplerate))
print("* quantité de son à 5% -> " + str(np.sum(abs(data[d:d+int(np.round(0.05*(f-d)))]))/np.sum(abs(data[d:f]))))
print("* f0 -> " + str(int(np.round(freqArray[i]))) + "Hz")
print("* duration -> " + str(np.round((f-d)/samplerate,2)) + "s")
print("* quantité de son à 5% -> " + str(np.round(np.sum(abs(data[d:d+int(np.round(0.05*(f-d)))]))/np.sum(abs(data[d:f])),2)) + "%")
print("* quantité de son à 50% -> " + str(np.round(np.sum(abs(data[d:d+int(np.round(0.5*(f-d)))]))/np.sum(abs(data[d:f])),2)) + "%")
print("* quantité de son à 5% -> " + str(np.round(np.sum(abs(data[d+int(np.round(0.95*(f-d))):f]))/np.sum(abs(data[d:f])),2)) + "%")
print("* amplitute max -> " + str(np.round(np.max(abs(data[d:f])))))
print("*************************")
print("")
print("_________________________")
......
......@@ -11,6 +11,7 @@ import matplotlib.pyplot as plt
import numpy as np
import frequency_estimator as f0
import os
from time import time
def listen(nom,sampleRate, data):
......@@ -24,7 +25,7 @@ def aff(titre,x,y):
plt.title(titre)
plt.show()
def decouperExtraits(data, seuil, dureeSilence, sampleRate, sampleRateChoosen):
def decouperExtraits(data, seuil, dureeSilence, sampleRate, sampleRateChoosen, start_time):
DATA=[]
onAir=False
step=int(np.round(sampleRateChoosen*dureeSilence))
......@@ -35,7 +36,7 @@ def decouperExtraits(data, seuil, dureeSilence, sampleRate, sampleRateChoosen):
f=0
for i in range(0,int(np.round(dureeExtrait)*sampleRateChoosen-step)-1000):
if (i%40000==0):
afficherAvancement(i,int(np.round(dureeExtrait)*sampleRateChoosen-step)-1000)
afficherAvancement(start_time, i,int(np.round(dureeExtrait)*sampleRateChoosen-step)-1000)
if ((abs(data[int(np.round(i*echelle))])<seuil) & onAir):
if(k<step):
k+=1
......@@ -56,18 +57,21 @@ def decouperExtraits(data, seuil, dureeSilence, sampleRate, sampleRateChoosen):
DATA.append([d,len(data)-1])
return DATA
def afficherAvancement(t,T):
def afficherAvancement(start_time,t,T):
os.system('clear')
barre = "|"
for i in range(int(np.round(np.round(t/T,2)*50))):
for i in range(int(np.round(np.round(t/T,2)*40))):
barre += "#"
for i in range(50-int(np.round(np.round(t/T,2)*50))):
for i in range(40-int(np.round(np.round(t/T,2)*40))):
barre += "_"
barre +="| "
barre += str(np.round(t/T,2)) + " %"
barre += str(np.round(t/T,2)*100) + " %"
temps_restant = (start_time-time())*(1/np.round(t/T,2) - 1)
barre += " | Ecoulé : " + str(abs(np.round((start_time-time())/60))) +"m"
barre += " | Reste : " + str(abs(np.round(temps_restant/60))) +"m"
print(barre)
def garderUniquementCris(sampleRate,tMin, tMax, fMin, fMax, f0Func, dataCut, data):
def garderUniquementCris(sampleRate,tMin, tMax, fMin, fMax, seuilA5, f0Func, dataCut, data):
nSamplesMin = tMin*sampleRate
nSamplesMax = tMax*sampleRate
res=[]
......@@ -80,21 +84,9 @@ def garderUniquementCris(sampleRate,tMin, tMax, fMin, fMax, f0Func, dataCut, dat
if((freq>fMin) & (freq<fMax)):
quantiteDeSonA5Pourcents = np.sum(abs(data[d:d+int(np.round(0.05*(f-d)))]))
quantiteDeSon = np.sum(abs(data[d:f]))
if (quantiteDeSonA5Pourcents / quantiteDeSon > 0.065):
if (quantiteDeSonA5Pourcents / quantiteDeSon > seuilA5):
res.append(dataCut[i])
freqs.append(freq)
listen("output/cri"+str(i)+".wav", sampleRate, np.asarray(data[d:f]))
print("*************************")
print("* enregistrement: " + str(i))
print("*************************")
print("* f0 -> " + str(freq))
print("* duration -> " + str((f-d)/sampleRate))
print("* quantité de son à 5% -> " + str(np.sum(abs(data[d:d+int(np.round(0.05*(f-d)))]))/np.sum(abs(data[d:f]))))
print("*************************")
print("")
print("_________________________")
print("")
return res, freqs
......
......@@ -83,8 +83,9 @@ def freq_from_HPS(sig, fs):
a = copy(c[::x]) # Should average or maximum instead of decimating
c = c[:len(a)]
i = argmax(abs(c))
true_i = parabolic(abs(c), i)[0]
res = fs * true_i / len(windowed)
#true_i = parabolic(abs(c), i)[0]
#res = fs * true_i / len(windowed)
res = fs * i / len(windowed)
resarray.append(res)
c *= a
show()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment