Python 3.10.12 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 19:09:20) [MSC v.1916 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.


IPython 8.12.0 -- An enhanced Interactive Python.


Restarting kernel...


In [1]: """

   ...:

   ...: objective: This is to check if audio file contains music or abnormal sound

   ...: Note: this code needs to run on super computers for the full dataset. The log file is produced on a test sample

   ...: """

   ...:

   ...:

   ...: import os

   ...: import csv

   ...: import glob

   ...: import scipy

   ...: import sklearn

   ...: import numpy as np

   ...: import hmmlearn.hmm

   ...: import sklearn.cluster

   ...: import pickle as cpickle

   ...: import matplotlib.pyplot as plt

   ...: from scipy.spatial import distance

   ...: import sklearn.discriminant_analysis

   ...: import pandas as pd

   ...: from pyAudioAnalysis import audioBasicIO

   ...: from pyAudioAnalysis import MidTermFeatures as mtf

   ...: from pyAudioAnalysis import ShortTermFeatures as stf

   ...: from pyAudioAnalysis import audioSegmentation as aS

   ...: from urllib.parse import unquote

   ...: from pydub import AudioSegment

   ...: import operator

   ...: import wave

   ...: import traceback

   ...: import time

   ...: import re

   ...:

   ...:

   ...:

   ...: data_path = r"C:\Users\nargolsh\pyAudioAnalysis"

   ...:

   ...:

   ...: def check_consecutive(lst):

   ...: count = 1

   ...: for i in range(1, len(lst)):

   ...: #print(lst[i])

   ...: if lst[i] == lst[i-1] + 1:

   ...: count += 1

   ...: #print(count)

   ...: if count >= 10:

   ...: return True

   ...: else:

   ...: count = 1

   ...: return False

   ...:

   ...:

   ...: audio_folder=r"D:\OneDrive - Indiana University\JAR Registered Report\Final_version_submisison\data\diarization_test\audio_inputs"

   ...:

   ...: filenames_to_save = []

   ...:

   ...: for filename in os.listdir(audio_folder):

   ...: csv_file_name=filename[-4]

   ...: audio_file=os.path.join(audio_folder, filename)

   ...: [flagsInd, classesAll, acc, CM] = aS.mid_term_file_classification(audio_file, data_path + "\data\models\svm_rbf_sm", "svm", False, 'D:\OneDrive - Indiana University\JAR Registered Report\Final_version_submisison\data\diarization_test\test.segments')

   ...: music_flag=pd.DataFrame(flagsInd,columns=['music_flag'])

   ...: music_flag=music_flag[music_flag['music_flag']==1]

   ...: music_flag.to_csv(f"D:\OneDrive - Indiana University\JAR Registered Report\Final_version_submisison\data\diarization_test\seconds_of_music_in_files\{csv_file_name}.csv")

   ...: index_list=music_flag.index.tolist()

   ...: if check_consecutive(index_list)==True:

   ...: filenames_to_save.append(filename)

   ...:

   ...: with open(r"D:\OneDrive - Indiana University\JAR Registered Report\Final_version_submisison\data\diarization_test\files_containing_music.txt", "w") as f:

   ...: for name in filenames_to_save:

   ...: f.write(f"{name}\n")

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(

C:\Users\nargolsh\AppData\Roaming\Python\Python310\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator SVC from version 0.23.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:

https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations

warnings.warn(


In [2]: