first commit

This commit is contained in:
kicap1992
2022-03-21 00:20:19 +08:00
commit e900081dc7
31 changed files with 640 additions and 0 deletions

File diff suppressed because one or more lines are too long

210
Pengujian Notebook.ipynb Normal file

File diff suppressed because one or more lines are too long

124
app.py Normal file
View File

@ -0,0 +1,124 @@
import librosa
import librosa.display as display
import matplotlib.pyplot as plt
import math
y1, sr1 = librosa.load('tp4.wav')
y2, sr2 = librosa.load('t2.wav')
def dot(A,B):
return (sum(a*b for a,b in zip(A,B)))
def cosine_similarity(a,b):
return dot(a,b) / ( (dot(a,a) **.5) * (dot(b,b) ** .5) )
def cosine_similarity1(v1,v2):
"compute cosine similarity of v1 to v2: (v1 dot v2)/{||v1||*||v2||)"
sumxx, sumxy, sumyy = 0, 0, 0
for i in range(len(v1)):
x = v1[i]; y = v2[i]
sumxx += x*x
sumyy += y*y
sumxy += x*y
return sumxy/math.sqrt(sumxx*sumyy)
#Showing multiple plots using subplot
plt.subplot(1, 2, 1)
mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC values
display.specshow(mfcc1)
plt.subplot(1, 2, 2)
mfcc2 = librosa.feature.mfcc(y2, sr2)
display.specshow(mfcc2)
from dtw import dtw
from numpy.linalg import norm
dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))
print('Normalized distance between the two sounds: '+ dist.__str__())
# import numpy as np
# array1 = np.array(mfcc1)
# array2 = np.array(mfcc2)
# number_of_equal_element = np.sum(array1 == array2)
# total_elements = np.multiply(*array1.shape)
# percentage = number_of_equal_element/total_elements
# print('Number of equal elements: '+ format(number_of_equal_element))
# print('number of identical elements: \t\t{}'.format(number_of_equal_element))
# print('number of different elements: \t\t{}'.format(total_elements-number_of_equal_element))
# print('percentage of identical elements: \t{:.2f}%'.format(percentage*100))
array1 = []
for nums in mfcc1:
for val in nums:
array1.append(val)
array2 = []
for nums in mfcc2:
for val in nums:
array2.append(val)
print(cosine_similarity(array1, array2))
# print(array1)
# print(array2)
# set1 = set(array1)
# set2 = set(array2)
# total = sorted(set1|set2)
# new_list1 = [x if x in set1 else "MISSING" for x in total]
# new_list2 = [x if x in set2 else "MISSING" for x in total]
# # print(new_list1)
# # print(new_list2)
# from numpy import dot
# from numpy.linalg import norm
# cos_sim = dot(new_list1, new_list2) / (norm(new_list1) * norm(new_list2))
# print('Cosine similarity: '+ cos_sim.__str__())
# def cosine_similarity1(v1,v2):
# # "compute cosine similarity of v1 to v2: (v1 dot v2)/{||v1||*||v2||)"
# sumxx, sumxy, sumyy = 0, 0, 0
# for i in range(len(v1)):
# x = v1[i]; y = v2[i]
# sumxx += x*x
# sumyy += y*y
# sumxy += x*y
# return sumxy/math.sqrt(sumxx*sumyy)
# -------------------------------------------------------#
# hop_length = 1024
# y_ref, sr = librosa.load("t1.wav")
# y_comp, sr = librosa.load("coba.wav")
# chroma_ref = librosa.feature.chroma_cqt(y=y_ref,
# sr=sr,hop_length=hop_length)
# chroma_comp = librosa.feature.chroma_cqt(y=y_comp,
# sr=sr, hop_length=hop_length)
# x_ref = librosa.feature.stack_memory(
# chroma_ref, n_steps=10, delay=3)
# x_comp = librosa.feature.stack_memory(
# chroma_comp, n_steps=10, delay=3)
# xsim = librosa.segment.cross_similarity(x_comp, x_ref)
# # print(xsim)
# fig, ax = plt.subplots()
# display.specshow(xsim, x_axis='s', y_axis='time', hop_length=hop_length, ax=ax)
# plt.show()
# ------------------------------------------------ #
# plt.imshow(cost.T, origin='lower', cmap=plt.get_cmap('gray'), interpolation='nearest')
# plt.plot(path[0], path[1], 'w') #creating plot for DTW
# plt.show()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bacaan/ustazah/b&t/b1.wav Normal file

Binary file not shown.

BIN
bacaan/ustazah/b&t/b2.wav Normal file

Binary file not shown.

BIN
bacaan/ustazah/b&t/t1.wav Normal file

Binary file not shown.

BIN
bacaan/ustazah/b&t/t2.wav Normal file

Binary file not shown.

7
readme.md Normal file
View File

@ -0,0 +1,7 @@
### ini merupakan pengujian untuk aplikasi bacaan_tulusan_arab menggunakan python jupyter notebook
### audio kemudiannya diload oleh librosa dengan menggunakan librosa.load() dan menggunakan mfcc() untuk menconvert audio ke dalam bentuk mfcc 2D list
### dimana dengan menggunakan librosa akan dapat menampilkan visualisasi antara 2 audio dengan menggunakan librosa.display.specshow()
### audio yang diconvert menjadi mfcc 2D list akan diconvert menjadi 1D list untuk dicheck similarity dengan menggunakan consine similarity
### terdapat juga normalize distance yang mana jika mendekati 0 maka suara sama
### sound similarity metode menggunakan cosine similarity

BIN
spec.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
spec1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

40
test.py Normal file
View File

@ -0,0 +1,40 @@
import cv2 as cv
import numpy as np
base = cv.imread('spec.png')
test = cv.imread('spec1.png')
# test2 = cv.imread('test2.jpg')
hsv_base = cv.cvtColor(base, cv.COLOR_BGR2HSV)
hsv_test = cv.cvtColor(test, cv.COLOR_BGR2HSV)
# hsv_test2 = cv.cvtColor(test2, cv.COLOR_BGR2HSV)
h_bins = 50
s_bins = 60
histSize = [h_bins, s_bins]
h_ranges = [0, 180]
s_ranges = [0, 256]
ranges = h_ranges + s_ranges
channels = [0, 1]
hist_base = cv.calcHist([hsv_base], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_base, hist_base, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
hist_test = cv.calcHist([hsv_test], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_test, hist_test, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
# hist_test2 = cv.calcHist([hsv_test2], channels, None, histSize, ranges, accumulate=False)
# cv.normalize(hist_test2, hist_test2, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
compare_method = cv.HISTCMP_CORREL
base_base = cv.compareHist(hist_base, hist_base, compare_method)
base_test = cv.compareHist(hist_base, hist_test, compare_method)
# base_test2 = cv.compareHist(hist_base, hist_test2, compare_method)
print('base_base Similarity = ', base_base)
print('base_test Similarity = ', base_test)
# print('base_test2 Similarity = ', base_test2)
cv.imshow('base',base)
cv.imshow('test1',test)
# cv.imshow('test2',test2)
# cv.waitKey(0)