Audio 在praat中连接多个wav文件

Audio 在praat中连接多个wav文件,audio,praat,Audio,Praat,我有一个文件夹,包含从1到20的wav文件,例如1.wav、2.wav….、20.wav等。我想串行连接它,但它不是串行连接。请建议一些帮助 我正在使用以下代码: form Concatenate sound files comment Directory of input sound files text Sound_directory C:\temp\ sentence Sound_file_extension .wav comment Save th

我有一个文件夹,包含从1到20的wav文件,例如1.wav、2.wav….、20.wav等。我想串行连接它,但它不是串行连接。请建议一些帮助

我正在使用以下代码:

    form Concatenate sound files
    comment Directory of input sound files
    text Sound_directory C:\temp\
    sentence Sound_file_extension .wav
    comment Save the final file as
    text Save_as C:\temp\temp.wav
endform

# Here, you make a listing of all the sound files in the specified directory.

Create Strings as file list... list 'sound_directory$'*'sound_file_extension$'
numberOfFiles = Get number of strings

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

Write to WAV file... 'save_as$'

select all
Remove
我找到了解决办法 当我创建字符串列表时 创建字符串作为文件列表

它按字母顺序创建一个列表


所以你得到1.wav,10.wav,11.wav,…2.wav,20.wav…等等,如果我把我的文件重命名为01.wav;02.wav,上面的代码很好。

可能有点复杂,但是您也可以使用
表的
排序
命令来模拟
字符串的一种通用排序。我已经尝试了几个测试用例,它似乎做得很好(对于黑客来说)

我添加了对多个
字符串的支持和一个不区分大小写的排序选项。选项的默认值是需要最少工作量的值。以下是脚本:

form Generic sort...
  boolean Numeric_first yes
  boolean Case_sensitive yes
endform

n = numberOfSelected("Strings")
for i to n
  strings[i] = selected("Strings", i)
endfor

for i to n
  # stopwatch

  selectObject(strings[i])
  nstrings = Get number of strings

  # Create an empty table
  cols$ = "num str"
  if !case_sensitive
    cols$ = cols$ + " lc"
  endif
  table = Create Table with column names: "nums", nstrings, cols$

  # Populate the table with the strings or their number versions where possible
  for row to nstrings
    selectObject(strings[i])
    s$ = Get string: row
    s = number(s$)

    selectObject(table)
    Set string value: row, "str", s$
    if !case_sensitive
      Set string value: row, "lc", replace_regex$(s$, "(.*)", "\L\1", 0)
    endif
    Set numeric value: row, "num", number(s$)
  endfor

  sort$ = "num " + if case_sensitive then "str" else "lc" fi
  Sort rows: sort$

  # Invert order for non-numeric strings first
  if !numeric_first
    selectObject(table)
    nantable = nowarn Extract rows where column (text):
      ..."num", "is equal to", "--undefined--"
    selectObject(table)
    numtable = nowarn Extract rows where column (text):
      ..."num", "is not equal to", "--undefined--"
    removeObject(table)
    selectObject(nantable, numtable)
    table = Append
    removeObject(nantable, numtable)
  endif

  # Replace the original strings with the sorted list
  selectObject(table)
  for row to nstrings
    selectObject(table)
    s$ = Get value: row, "str"
    selectObject(strings[i])
    Set string: row, s$
  endfor

  # Clean-up
  removeObject(table)

  # selectObject(strings[i])
  # name$ = selected$("Strings")
  # time = stopwatch
  # appendInfoLine("Sorted ", name$ , " in ", time)
endfor

# Restore selection
if n >= 1
  selectObject(strings[1])
  for i from 2 to n
    plusObject(strings[i])
  endfor
endif
编辑 CPrAN插件中包含了此脚本的一部分