Last active
May 12, 2016 13:41
-
-
Save psibre/f688aedb103d2cc8e320a71073c7a7d2 to your computer and use it in GitHub Desktop.
Praat script to concatenate recoverably from list of WAV files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
form Concatenate recoverably from list of WAV files | |
sentence File_list file.lst | |
sentence Output_file chain.wav | |
endform | |
clearinfo | |
output_file$ = if startsWith(output_file$, "/") or shellDirectory$ == "/" then output_file$ else shellDirectory$ + "/" + output_file$ fi | |
file_list$ = if startsWith(file_list$, "/") or shellDirectory$ == "/" then file_list$ else shellDirectory$ + "/" + file_list$ fi | |
Read Strings from raw text file... 'file_list$' | |
numberOfFiles = Get number of strings | |
for f to numberOfFiles | |
file_'f'$ = Get string... f | |
endfor | |
Remove | |
s = 0 | |
totalDuration = 0 | |
globalSamplingFrequency = 0 | |
globalNumberOfChannels = 0 | |
for f to numberOfFiles | |
file$ = if startsWith(file_'f'$, "/") or shellDirectory$ == "/" then file_'f'$ else shellDirectory$ + "/" + file_'f'$ fi | |
if not fileReadable(file$) | |
printline [ERROR] Cannot read file: 'file$' | |
goto continue | |
endif | |
sound = Read from file... 'file$' | |
samplingFrequency = Get sampling frequency | |
globalSamplingFrequency = if globalSamplingFrequency then globalSamplingFrequency else samplingFrequency fi | |
if samplingFrequency != globalSamplingFrequency | |
printline [ERROR] Sampling frequency ('samplingFrequency') differs from global sampling frequency ('globalSamplingFrequency') for file 'file$' | |
Remove | |
goto continue | |
endif | |
numberOfChannels = Get number of channels | |
globalNumberOfChannels = if globalNumberOfChannels then globalNumberOfChannels else numberOfChannels fi | |
if numberOfChannels != globalNumberOfChannels | |
printline [ERROR] Number of channels ('numberOfChannels') differs from global number of channels ('globalNumberOfChannels') for file 'file$' | |
Remove | |
goto continue | |
endif | |
if f == 1 | |
Save as WAV file... 'output_file$' | |
else | |
Append to existing sound file... 'output_file$' | |
endif | |
printline [INFO] Appended file 'file$' ('f'/'numberOfFiles') | |
s += 1 | |
sound_'s'_name$ = right$(file$, length(file$)- rindex(file$, "/")) - ".wav" | |
sound_'s'_duration = Get duration | |
totalDuration += sound_'s'_duration | |
Remove | |
label continue | |
endfor | |
printline [INFO] Wrote WAV file to 'output_file$' | |
Create TextGrid... 0 totalDuration labels | |
numberOfSounds = s | |
start = 0 | |
for s to numberOfSounds | |
sound$ = sound_'s'_name$ | |
if s > 1 | |
Insert boundary... 1 start | |
endif | |
Set interval text... 1 s 'sound$' | |
start += sound_'s'_duration | |
endfor | |
output_file$ = output_file$ - ".wav" + ".TextGrid" | |
Save as chronological text file... 'output_file$' | |
Remove | |
printline [INFO] Wrote TextGrid to 'output_file$' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment