Commit 3e46a6ca authored by Candre Nathan's avatar Candre Nathan
Browse files

Initial commit

parents
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 10:04:06 2021
@author: lucasdaniele
"""
from scipy.io import wavfile
import matplotlib.pyplot as plt
import numpy as np
import frequency_estimator.frequency_estimator as f0
def listen(nom,sampleRate, data):
wavfile.write(nom, sampleRate, data.real)
def aff(titre,x,y):
if(len(x)==len(y)):
plt.plot(x, y.real, "-")
else:
plt.plot(y.real, "-")
plt.title(titre)
plt.show();
def decouperExtraits(data):
DATA=[]
cut=[]
onAir=False
step=10000
k=0
seuil=1500
for i in range(step,len(data)):
if ((abs(data[i])<seuil) & onAir):
if(k<step):
k+=1
cut.append(data[i])
else:
k=0
onAir=False
DATA.append(cut)
cut=[]
else:
if(abs(data[i])>=seuil):
if(not(onAir)):
onAir=True
k=0
cut.append(data[i])
DATA.append(cut)
return DATA
def garderUniquementCris(sampleRate,tMin, tMax, fMin, fMax, f0Func, dataCut):
nSamplesMin = tMin*sampleRate
nSamplesMax = tMax*sampleRate
res=[]
for i in range(len(dataCut)):
if((len(dataCut[i])>nSamplesMin) & (len(dataCut[i])<nSamplesMax)):
freq = np.round(f0Func(np.asarray(dataCut[i]),sampleRate))
if((freq>fMin) & (freq<fMax)):
res.append(dataCut[i])
return res
\ No newline at end of file
frequency_estimator @ f94aa1d3
Subproject commit f94aa1d3d63a8ec3c0e80f30c6f9f4e375ceea0f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 24 21:25:34 2021
@author: lucasdaniele
"""
from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt
import fcts as fcts
################################################
# Extraction des données
################################################
#bEnSec = (4*60+43)
#bEnSec = (5*60+16)
bEnSec = (5*60+43.8)
duree = 0.7
samplerate, dataLR = wavfile.read("test1.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
T = 1/samplerate;
b = int(round(bEnSec*samplerate))
n = int(round(duree*samplerate));
t = np.linspace(bEnSec, bEnSec+n*T, n)
data = dataL[b:n+b]#On recupere n echantillons depuis b soit depuis bEnSec --> Support temporel
################################################
# Support temporel sans modifs
################################################
fcts.aff("Support temporel sans modifs",t,data)
fcts.listen("extrait.wav", samplerate, data)
################################################
# Support temporel sans silences
################################################
dataSansSilence = fcts.supprmierSilences(1500, data)
fcts.aff("Support temporel sans les silences",t,dataSansSilence)
fcts.listen("extraitSansSilence.wav", samplerate, dataSansSilence)
################################################
# Support frequentiel sans modifs
################################################
f,dataf = fcts.timeToFrequency(t, dataSansSilence)
# fcts.aff("Support frequentiel sans modifs",f,abs(dataf))
################################################
# Support frequentiel sans parasites
################################################
dataf = fcts.passeBas(1300,0,f,dataf)
# fcts.aff("Support frequentiel avec passe bas", f, abs(dataf))
################################################
# Support temporel sans parasites
################################################
dataSansBruit = fcts.frequencyToTime(f, dataf)
fcts.aff("Support temporel sans les parasites",t,dataSansBruit)
fcts.listen("extraitSansParasite.wav", samplerate, dataSansBruit)
# # ################################################
# # # Support frequentiel avec filtre anti balle
# # ################################################
# dataf = fcts.coupeBande(205,5,0,f,dataf)
# dataSansBalle = fcts.frequencyToTime(f, dataf)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 26 09:45:25 2021
@author: lucasdaniele
"""
from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt
import fcts as fcts
import frequency_estimator.frequency_estimator as f0
################################################
# Extraction des données
################################################
#bEnSec = (4*60+43)
#bEnSec = (5*60+16)
bEnSec = (3600+21*60+34)
duree = 300
samplerate, dataLR = wavfile.read("input/male.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
T = 1/samplerate;
b = int(round(bEnSec*samplerate))
n = int(round(duree*samplerate));
t = np.linspace(bEnSec, bEnSec+n*T, n)
data = dataL[b:n+b]#On recupere n echantillons depuis b soit depuis bEnSec --> Support temporel
################################################
# Support temporel sans modifs
################################################
fcts.aff("Support temporel sans modifs",t,data)
fcts.listen("output/extrait.wav", samplerate, data)
################################################
# Support temporel signal découpé
################################################
dataCut = fcts.decouperExtraits(data)
################################################
# Support temporel uniquement cris
################################################
dataCutCris = fcts.garderUniquementCris(samplerate,0.3,1,900,1000,f0.freq_from_crossings, dataCut)
for i in range(len(dataCutCris)):
fcts.aff("cri"+str(i), t, np.asarray(dataCutCris[i]))
fcts.listen("output/cri"+str(i)+".wav", samplerate, np.asarray(dataCutCris[i]))
print("enregistrement: " + str(i))
print(np.round(f0.freq_from_crossings(np.asarray(dataCutCris[i]),samplerate)))
print("________________")
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 26 15:58:02 2021
@author: lucasdaniele
"""
import fcts as fcts
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
import scipy.signal
bEnSec = (5*60+43)
duree = 5
fe, dataLR = wavfile.read("test1.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
te = 1/fe;
b = int(round(bEnSec*fe))
n = int(round(duree*fe));
t = np.linspace(bEnSec, bEnSec+n*te, n)
x = dataL[b:n+b]#On recupere n echantillons depuis b soit depuis bEnSec --> Support temporel
plt.plot(t,x);
fcts.listen("extrait.wav", fe, np.asarray(x))
plt.show();
fca = 200 # frequence de coupure basse
fcb = 210 # coupure haute
a = fca/fe
b = fcb/fe
P = 50
h = fcts.filtreRIF("CBande",a,b,P,"hann")
[f,g,phi] = fcts.reponseFreq(h)
y = scipy.signal.convolve(x,h,mode='valid')
ny = y.size
ty = np.zeros(ny)
for k in range(ny):
ty[k] = P*te+te*k
plt.plot(ty,y);
fcts.listen("extraitFiltre.wav", fe, np.asarray(y))
plt.show();
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 28 16:42:37 2021
@author: lucasdaniele
"""
from scipy.io import wavfile
import numpy as np
samplerate, d1 = wavfile.read("cri.wav")
superD1 = np.zeros(int(np.ceil(len(d1)/10)))
for i in range(len(d1)):
if(i%3==0):
superD1[int(np.floor(i/10))]=d1[i]
samplerate, d0 = wavfile.read("extrait.wav")
superD0 = np.zeros(int(np.ceil(len(d0)/10)))
for i in range(len(d0)):
if(i%3==0):
superD0[int(np.floor(i/10))]=d0[i]
T = 1/samplerate;
max_=0
for i in range(0,len(superD0)-len(superD1),1):
corr = np.corrcoef(superD0[i:i+len(superD1)],superD1)[0,1]
if (corr>max_):
max_ = corr
print(corr, i)
print(max_)
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