<jupyter_start><jupyter_text>以下測試MFCC<jupyter_code>basePathOfTrainData = "../DysSpeech_Corpora/Linzy/linzyCut/train/"
def getNextLevelDirs(root):
     return next(os.walk(root))[1]

def getAllWavFiles():
    _baseDir = '../DysSpeech_Corpora/Linzy/linzyCut/train/'
    firstLevelDirs = getNextLevelDirs(_baseDir)
    trainfiles = list()
    for folder in firstLevelDirs:
        d = os.path.join(_baseDir,folder)
        #print(d)
        #files = [os.path.join(d,f+'.npy') for f in next(os.walk(d))[2] if f.endswith('.wav')]
        files = [os.path.join(d,f) for f in next(os.walk(d))[2] if f.endswith('.wav')]
        #print(files)
        #trainfiles.append([os.path.join(d,f+'.npy') for f in next(os.walk(d))[2] if f.endswith('.wav')])
        trainfiles += files
    
def getAllFolder():
    _baseDir = '../DysSpeech_Corpora/Linzy/linzyCut/train/'
    firstLevelDirs = getNextLevelDirs(_baseDir)
    print("firstLevelDirs : ", firstLevelDirs)
    return firstLevelDirs

ALL_Folders = getAllFolder()   
#labelDict = {1:'one','14next':, '18right', '11up', '17left', , '15in', '10close', '16out', '19home',, '13previous', '12down'}
folderList = ['1','2','3','4','5','6','7','8','9','10', '11', '12','13','14', '15','16','17','18','19']
DSCmdLabels = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'close', 'up', 'down', 'previous', 'next', 'in', 'out', 'left', 'right', 'home']
def save_data_to_array(rootPath, targetDir):
    #labels, _, _ = get_labels(path)

    for folder in folderList:#DYSCmdCategString:
        # Init mfcc vectors
        mfcc_vectors = []
        wavfiles = [rootPath + folder +"/"+ wav for wav in os.listdir(rootPath + folder+'/') if wav.endswith('.wav')]#if wavfile.endswith('.wav')
        #wavfiles = [wavfile for wavfile in ]
        print("Current folder is : ",folder)
        #print("the whole files are : ",wavfiles)
        #print("+++++++++++++++++++++++++++++++++++++")
        for _wav in wavfiles:#tqdm(wavfiles, "Saving vectors of label - '{}'".format(folder)):
            #mfcc_ = wav2mfcc(wavfile)
            mfcc_ = calculateMFCC(_wav)
            mfcc_vectors.append(mfcc_)
        print("length of mfcc_vectors is : ",len(mfcc_))
        np.save(targetDir+folder + '.npy', mfcc_vectors)
save_data_to_array()
#read all the audio data and convert them into mfcc
testFile = DYData_Path+"13previous/LinZY03_13_3.wav"
def testWavToMFCC(anAudioFile):
    mfcc = wav2mfcc(anAudioFile)
    return mfcc

#_mfcc = testWavToMFCC(testFile)
    
#print("type of mfcc : ",type(_mfcc))
#print("shape of mfcc : ",_mfcc.shape)
from subprocess import call
def extract_loudest_section(path=basePathOfTrainData):
    #labels, _, _ = get_labels(path)
    targetD = 0
    for folder in folderList:#DYSCmdCategString:
        # Init mfcc vectors
        #mfcc_vectors = []
        targetD +=1
        targetDName = "./template/dir/" + str(targetD)
        wavfiles = [basePathOfTrainData + folder +"/"+ wavfile for wavfile in os.listdir(path + folder+'/') if wavfile.endswith('.wav')]#if wavfile.endswith('.wav')
        #wavfiles = [wavfile for wavfile in ]
        print("Current folder is : ",folder)
        #print("the whole files are : ",wavfiles)
        #print("+++++++++++++++++++++++++++++++++++++")
        
        for wavfile in wavfiles:#tqdm(wavfiles, "Saving vectors of label - '{}'".format(folder)):
            #mfcc_ = wav2mfcc(wavfile)
            #mfcc_vectors.append(mfcc_)
            #wavfile = os.path.splitext(wavfile)[0]
            print("processing file {}".format(wavfile))
            call(["./extract_loudest_section", wavfile, targetDName])
            
        #print("length of mfcc_vectors is : ",len(mfcc_))
        #np.save(folder + '.npy', mfcc_vectors)
extract_loudest_section()
def makedir(parentPath):
    #basepath = "./template/dirtemplate/"
    for idx in range(19):
        dirname = parentPath+str((idx+1))
        print("making dir {}".format(dirname))
        os.makedirs(dirname)
makedir("../DysSpeech_Corpora/DrSun/rawData/")<jupyter_output>making dir ../DysSpeech_Corpora/DrSun/rawData/1
making dir ../DysSpeech_Corpora/DrSun/rawData/2
making dir ../DysSpeech_Corpora/DrSun/rawData/3
making dir ../DysSpeech_Corpora/DrSun/rawData/4
making dir ../DysSpeech_Corpora/DrSun/rawData/5
making dir ../DysSpeech_Corpora/DrSun/rawData/6
making dir ../DysSpeech_Corpora/DrSun/rawData/7
making dir ../DysSpeech_Corpora/DrSun/rawData/8
making dir ../DysSpeech_Corpora/DrSun/rawData/9
making dir ../DysSpeech_Corpora/DrSun/rawData/10
making dir ../DysSpeech_Corpora/DrSun/rawData/11
making dir ../DysSpeech_Corpora/DrSun/rawData/12
making dir ../DysSpeech_Corpora/DrSun/rawData/13
making dir ../DysSpeech_Corpora/DrSun/rawData/14
making dir ../DysSpeech_Corpora/DrSun/rawData/15
making dir ../DysSpeech_Corpora/DrSun/rawData/16
making dir ../DysSpeech_Corpora/DrSun/rawData/17
making dir ../DysSpeech_Corpora/DrSun/rawData/18
making dir ../DysSpeech_Corpora/DrSun/rawData/19<jupyter_text><jupyter_code>def getWavFileList(parentPath=None):
    wavfiles = [os.path.join(parentPath,wavfile) for wavfile in os.listdir(parentPath) 
                if wavfile.endswith('rec.wav')]
    return wavfiles
    #[parentPath+ wavfile for wavfile in os.listdir(parentPath) if wavfile.endswith('rec.wav')]

def extract_loudest_section(sourceParentDir,targetParentDir):
    wavfilelist = None
    for idx in range(19):
        currentTargetDir = str((idx+1))
        sourceDir = os.path.join(sourceParentDir,currentTargetDir)
        #print("source dir is {}".format(sourceDir))
        targetDir = os.path.join(targetParentDir,currentTargetDir)
        wavfilelist = getWavFileList(sourceDir)
        for wavfile in wavfilelist:
            subprocess.call(["./extract_loudest_section", wavfile, targetDir])
    
extract_loudest_section("../DysSpeech_Corpora/DrSun/train/","../DysSpeech_Corpora/DrSun/rawData/")
testWavList = getWavFileList("../DysSpeech_Corpora/DrSun/train/1/")
print(testWavList)
#get mfacc of drsun
save_data_to_array("../DysSpeech_Corpora/DrSun/train/","./DrSun_MFCC/")<jupyter_output>Current folder is :  1
{'fraction_non_alphanumeric': 0.1630078636959371, 'fraction_numerical': 0.01703800786369594, 'mean_word_length': 3.7583787996882307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '405948', 'license': 'MIT', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2227, 'n_words': 394, 'path': 'Test_Misc.ipynb', 'repo_name': 'xrick/LcjDysarthriaSpeechCommandRecognier', 'size': '6104'}