Upload files to ''
This commit is contained in:
parent
6e83281703
commit
79ca3cf6ab
48
CorrelationCoefficient.py
Normal file
48
CorrelationCoefficient.py
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import thinkdsp
|
||||
|
||||
|
||||
|
||||
|
||||
#segment: ebben a hangmintaban keressuk az eredeti hangmintaval "original_sample" leginkabb korrelalo reszt
|
||||
#original_sample: az eredeti madarhang minta
|
||||
# A fuggveny a bemeneti hangmintat mintavetelenkent osszehasonlitja az altalunk keresett hangmintaval es vissza adja annak
|
||||
# a maximalis korrelaciot.
|
||||
def calculatecorr(segment,original_sample):
|
||||
maxcorr = 0
|
||||
time = 0
|
||||
#1minta 1 masodperc(framerate szama = utolso elem)
|
||||
lastsample = segment.framerate
|
||||
for timestamp in segment.ts[:-lastsample]:
|
||||
#mindig az adott mintaveteltol szamitott 1mp-es mintat vesszuk
|
||||
segment_chunk = segment.segment(start=timestamp, duration=1)
|
||||
#Correlation coefficient two waves.
|
||||
correlation = original_sample.corr(segment_chunk)
|
||||
if correlation > maxcorr :
|
||||
maxcorr = correlation
|
||||
time = timestamp
|
||||
print(correlation)
|
||||
if maxcorr > 0.9:
|
||||
return maxcorr
|
||||
break
|
||||
|
||||
print("Vegeredmeny:")
|
||||
print(maxcorr)
|
||||
print("Masodperc:")
|
||||
print(time)
|
||||
return maxcorr
|
||||
|
||||
|
||||
|
||||
|
||||
sturnusVulgaris = thinkdsp.read_wave("wavs/sturnus/CommonStarling_100962.wav")
|
||||
train_sample = sturnusVulgaris.segment(start=4,duration=1)
|
||||
test_sample = sturnusVulgaris.segment(start=0,duration=5)
|
||||
|
||||
|
||||
calculatecorr(test_sample,train_sample)
|
||||
|
||||
|
||||
|
40
calculator.py
Normal file
40
calculator.py
Normal file
@ -0,0 +1,40 @@
|
||||
import sys
|
||||
sys.version = '3.6.7 (default, Nov 6 2019, 16:19:42) \n[GCC 7.3.0]'
|
||||
sys.path.append('thinkdsp/')
|
||||
import thinkdsp
|
||||
#segment: ebben a hangmintaban keressuk az eredeti hangmintaval "original_sample" leginkabb korrelalo reszt original_sample: az eredeti madarhang minta
|
||||
# A fuggveny a bemeneti hangmintat mintavetelenkent osszehasonlitja az altalunk keresett hangmintaval es vissza adja annak a maximalis korrelaciot.
|
||||
from flask import request, session, app
|
||||
from flask import current_app
|
||||
from datetime import datetime
|
||||
def main():
|
||||
current_app.logger.info("Received request")
|
||||
now = datetime.now()
|
||||
current_time = now.strftime("%H:%M:%S")
|
||||
output = ""
|
||||
output = output + "Elinditva:" + current_time + "\n"
|
||||
maxcorr = 0
|
||||
time = 0
|
||||
filename_raw = str(request.get_data())
|
||||
filename = filename_raw[2:-1]
|
||||
sturnusVulgaris = thinkdsp.read_wave("wavs/%s.wav" % filename)
|
||||
train_sample = sturnusVulgaris.segment(start=4,duration=1)
|
||||
test_sample = sturnusVulgaris.segment(start=0,duration=5)
|
||||
segment = test_sample
|
||||
original_sample = train_sample
|
||||
#sturnusVulgaris = thinkdsp.read_wave(filename) 1minta 1 masodperc(framerate szama = utolso elem)
|
||||
lastsample = segment.framerate
|
||||
for timestamp in segment.ts[:-lastsample]:
|
||||
#mindig az adott mintaveteltol szamitott 1mp-es mintat vesszuk
|
||||
segment_chunk = segment.segment(start=timestamp, duration=1)
|
||||
#Correlation coefficient two waves.
|
||||
correlation = round(original_sample.corr(segment_chunk),8)
|
||||
if correlation > maxcorr :
|
||||
maxcorr = correlation
|
||||
time = timestamp
|
||||
output = str(output) + str(round(correlation,8)) + "\n"
|
||||
if maxcorr > 0.9:
|
||||
output = output + str(maxcorr)
|
||||
end = datetime.now()
|
||||
end_time = end.strftime("%H:%M:%S")
|
||||
return output + "\nVegeredmeny:\n" + str(maxcorr) + "\nMasodperc:\n" + str(time) + "\nBefejezve:"+ end_time
|
Loading…
Reference in New Issue
Block a user