2016-09-16 44 views
0

我有以下問題:我想低通濾波器240 WAV文件。該腳本僅在創建低通濾波聲音並顯示在對象列表(「..._ band」)中之前運行。但是,Praat不會將它們導出爲WAV文件。選擇輸出文件夾後,我會收到警告消息「Command」獲取字符串數量「不適用於當前選擇」。如何將操縱的WAV文件保存在對象列表中?

總之,我的問題是如何將WAV聲音保存到對象列表中,並使用它們的新文件名?另見Screenshot

腳本見下文。

非常感謝您的幫助!

問候,

#determine praat version 
ver1$ = left$(praatVersion$, (rindex(praatVersion$, ".")-1)); 
ver1 = 'ver1$' 
if ver1 < 5.2 
    exit Please download a more recent version of Praat 
endif 

if ver1 == 5.2 
    ver2$ = right$(praatVersion$, length(praatVersion$) - (rindex(praatVersion$, "."))); 
    ver2 = 'ver2$' 
    if ver2 < 4 
     exit Please download a more recent version of Praat (minor) 
    endif 
endif 

beginPause ("Low-Pass Filter Instructions") 
    comment ("1. Select a folder containing the wave files to be low-pass filtered") 
    comment ("2. Wave files will be low-pass filtered (0 - 400 Hz)") 
    comment ("3. Select an output folder for the low-pass filtered wave files to be saved to") 
    comment ("Click 'Next' to begin") 
clicked = endPause("Next", 1); 

#wavefile folder path 
sourceDir$ = chooseDirectory$ ("Select folder containing wave files") 
if sourceDir$ == "" 
    exit Script exited. You did not select a folder. 
else 
    sourceDir$ = sourceDir$ + "/"; 
endif 

Create Strings as file list... list 'sourceDir$'/*.wav 

numberOfFiles = Get number of strings 
levels$ = "" 
for ifile to numberOfFiles 
    select Strings list 
    currentList = selected ("Strings") 
    filename$ = Get string... ifile 
    Read from file... 'sourceDir$'/'filename$' 
    currentSound = selected ("Sound") 
    filterFreqRange = Filter (pass Hann band)... 0 400 20 

    select currentSound 
    Remove 

endfor 

select currentList 
Remove 

#output folder path - where the wave files get saved 
outputDir$ = chooseDirectory$ ("Select folder to save wave files") 
if outputDir$ == "" 
    exit Script exited. You did not select a folder. 
else 
    outputDir$ = outputDir$ + "/"; 
endif 

numberOfFiles = Get number of strings 
for ifile to numberOfFiles 
    select Strings list 
    currentList = selected ("Strings") 
    filename$ = Get string... ifile 
    currentSound = selected ("Sound") 
    endif 
    Save as WAV file... 'outputDir$'/'filename$' 
    select currentSound 
    Remove 
endfor 

#clean up 
select currentList 
Remove 

#clear the info window 
clearinfo 
#print success message 
printline Successfully low-pass filtered 'numberOfFiles' wave files. 

回答

0

一目瞭然,該命令不可用,因爲當你到這一點在劇本的選擇是空的。它是空的,因爲在第一個循環結束時,你選擇了你的Strings對象,然後Remove它。

更一般地說,您的腳本沒有正確處理對象選擇,這是Praat中的一個大問題,因爲可用命令根據活動選擇而改變。

因此,即使您刪除了列表中的行,但在第二次運行Get number of strings時會遇到問題,因爲那樣您就改變了選擇。即使你刪除了那一行(你並不需要),當你在選擇Strings對象後運行selected("Sound")時,仍然會出現問題,因爲那時你將不會有任何選擇的Sound對象(無論如何你之前沒有他們)。

更地道版本的劇本,這也運行在一個單一的循環,聲音讀出,過濾,並逐一刪除,(這也是更多的內存效率)是這樣的:

form Low-Pass Filter... 
    real From_frequency_(Hz) 0 
    real To_frequency_(Hz) 400 
    real Smoothing_(Hz) 20 
    comment Leave paths empty for GUI selectors 
    sentence Source_dir 
    sentence Output_dir 
endform 

if praatVersion < 5204 
    exitScript: "Please download a more recent version of Praat" 
endif 

if source_dir$ == "" 
    source_dir$ = chooseDirectory$("Select folder containing wave files") 
    if source_dir$ == "" 
     exit 
    endif 
endif 

if output_dir$ == "" 
    output_dir$ = chooseDirectory$("Select folder to save filtered files") 
    if output_dir$ == "" 
     exit 
    endif 
endif 

list = Create Strings as file list: "list", source_dir$ + "/*.wav" 
numberOfFiles = Get number of strings 
levels$ = "" 

for i to numberOfFiles 
    selectObject: list 
    filename$ = Get string: i 
    sound = Read from file: source_dir$ + "/" + filename$ 
    filtered = Filter (pass Hann band): from_frequency, to_frequency, smoothing 

    Save as WAV file: output_dir$ + "/" + selected$("Sound") 
    removeObject: sound, filtered 
endfor 

雖然你可能有興趣知道,如果你不需要自動讀取和保存文件(也就是說,如果你的腳本可以在列表中的對象上工作),你的腳本可以縮減爲

Filter (pass Hann band): 0, 400, 20 

適用於多個選擇Sound對象。

如果您絕對需要循環(例如,如果您將處理的文件非常多),您可能也有興趣使用vieweach plugin,並試圖儘量減少這種樣板(完整免責聲明:我寫了插件)。我還寫了一個更長的blog post

+0

謝謝你的回答。不幸的是,這不符合你的建議。 – username

+0

我已經正確地確定了問題的根源,但不是其範圍。事實證明,你的腳本在選擇時遇到了很多問題。我用腳本的工作版本更新了我的答案,並提供了一些指向其他資源的鏈接。 – jja

+0

非常感謝您的幫助,jja !! 現在它工作,我改變了唯一的是以下,因爲它保存了沒有文件類型結尾的聲音: '另存爲WAV文件:output_dir $ +「/」+選中$(「Sound」)+「.wav 「' – username