######################## # # This script takes all the sound files in a selected # directory and concatenates them into a single sound # file. The final file is saved as specified. # Modified by Jevon Heath 2014-4-14. # ######################## form Concatenate sound files comment Directory of input sound files text Sound_directory /Users/Cadavaca/Desktop/ sentence Sound_file_extension .wav comment Save the final file as (no extension) text Save_in /Users/Cadavaca/Desktop/Complete files/ # Example: ".../Complete files/18read" in order to get both 18read.wav and 18read.txt endform # Here, you make a listing of all the sound files in the specified directory. stringslist = do ("Create Strings as file list...", "list", "'sound_directory$'*'sound_file_extension$'") numberOfFiles = Get number of strings # create array of file numbers for i from 1 to numberOfFiles istring$ = do$ ("Get string...", i) fsuffix = index_regex("'istring$'", "\d+\.wav") wavsuffix = index_regex("'istring$'", ".wav") filenumber = number(mid$ (istring$, fsuffix, wavsuffix - fsuffix)) a[i] = filenumber endfor call sort # sort procedure for file names procedure sort iPos = 1 iMin = 1 for iPos from 1 to numberOfFiles iMin = iPos for i from iPos + 1 to numberOfFiles if a[i] < a[iMin] iMin = i endif endfor if iMin <> iPos call swapNumbers iPos iMin endif endfor endproc procedure swapNumbers iPos iMin temp = a[iMin] a[iMin] = a[iPos] a[iPos] = temp select stringslist posstring$ = do$ ("Get string...", iPos) minstring$ = do$ ("Get string...", iMin) do ("Set string...", iPos, "'minstring$'") do ("Set string...", iMin, "'posstring$'") endproc procedure displayArray for i from 1 to numberOfFiles ans = a[i] printline 'ans' endfor endproc # Now open files (in their new order) for ifile to numberOfFiles select Strings list filename$ = Get string... ifile # A sound file is opened from the listing: Read from file... 'sound_directory$''filename$' endfor # Now, concatenate all files into a single file select all minus Strings list Concatenate # And save the resulting file do ("Write to WAV file...", "'save_in$'.wav") # Save text file list of strings select stringslist for i from 1 to numberOfFiles istring$ = do$ ("Get string...", i) fword = index_regex("'istring$'", "_.*_") + 1 if index_regex("'istring$'", "-") = 0 gsuffix = index_regex("'istring$'", "_\d+\.wav") else gsuffix = index_regex("'istring$'", "[^A-Z]*_\d+\.wav") endif filewordnumber$ = mid$ (istring$, fword, gsuffix - fword) do ("Set string...", i, "'filewordnumber$'") endfor do ("Save as raw text file...", "'save_in$'.txt") select all Remove