From 79ca3cf6ab90c52cd7c0a07f4179d3f4029bcc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 5 Mar 2020 16:46:40 +0100 Subject: [PATCH] Upload files to '' --- CorrelationCoefficient.py | 48 +++++++++++++++++++++++++++++++++++++++ calculator.py | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 CorrelationCoefficient.py create mode 100644 calculator.py diff --git a/CorrelationCoefficient.py b/CorrelationCoefficient.py new file mode 100644 index 0000000..f8654c0 --- /dev/null +++ b/CorrelationCoefficient.py @@ -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) + + + diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..d5c39dd --- /dev/null +++ b/calculator.py @@ -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 \ No newline at end of file