praat - удалить сегмент

У меня есть несколько речевых файлов, и мне нужно вырезать определенную часть звукового файла, от 0,21 миллисекунды до 0,45 миллисекунды. Сценарий ниже выберет звуковой сегмент от 0,21 миллисекунды до 0,45 миллисекунды и сохранит его. Я хочу вырезать сегмент из файла речи, а затем сохранить его без него. Вероятно, мне следует добавить еще одну строку после «Переместить конец выделения к ближайшему пересечению нуля» и изменить «Записать выбранный звук ...», но я не уверен, как именно.

form Files
    sentence InputDir  ./
endform

createDirectory ("output")
Create Strings as file list... list 'inputDir$'*.wav
numberOfFiles = Get number of strings

for ifile to numberOfFiles

    select Strings list
    fileName$ = Get string... ifile
    Read from file... 'inputDir$''fileName$'
    sound_name$ = selected$ ("Sound")

        select Sound 'sound_name$'
        Edit
        editor Sound 'sound_name$'
        Select... 0.21 0.45
        Move start of selection to nearest zero crossing
        Move end of selection to nearest zero crossing
        Write selected sound to WAV file... ./output/'fileName$'
        endeditor

    select all
    minus Strings list
    Remove

endfor

select all
Remove 

person linguist3930    schedule 06.11.2016    source источник


Ответы (1)


Я хочу вырезать фрагмент из файла речи, а затем сохранить его без него

Непонятно, что вы хотите делать с удаленным сегментом. Вы хотите отредактировать его (например, сократить общую продолжительность звука?) или просто заглушить его (например, установить нулевые сэмплы, содержащиеся в нем?).

В любом случае, вам не нужно открывать звуковой редактор (окно со звуковой волной и спектрограммой). Ниже я воспроизвел ваш скрипт с некоторыми альтернативами (и обновил синтаксис).

form Files
  sentence Input_dir  ./
  positive Start 0.21
  positive End 0.45
endform

createDirectory("output")
list = Create Strings as file list: "list", input_dir$ + "*.wav"
numberOfFiles = Get number of strings

for ifile to numberOfFiles
  selectObject: list
  fileName$ = Get string: ifile
  sound = Read from file: input_dir$ + fileName$
  sound_name$ = selected$("Sound")

  # Find zero crossings
  start = Get nearest zero crossing: 1, start
  end = Get nearest zero crossing: 1, end
  sound_end = Get total duration

  # Cut the selected part out, shortening the sound
  # by extracting the part before and after and concatenating
  before = Extract part: 0, start, "rectangular", 1, "no"
  selectObject: sound
  after  = Extract part: end, sound_end, "rectangular", 1, "no"
  selectObject: before, after
  new = Concatenate
  removeObject: before, after

  ## Or, if you want to set the selected part to zero
  ## (since we already have the zero crossings)
  # new = Set part to zero: start, end, "at exactly these times"

  ## Or, if what you want is to get only the selected part
  ## and not the original sound
  # new = Extract part: start, end, "rectangular", 1, "no"

  # Either way, the new, modified sound is selected
  # and its ID is stored in `new`

  Save as WAV file: "./output/" + fileName$

  # I prefer a less shotgunny way to remove unwanted objects
  removeObject: sound, new
endfor

removeObject: list
person jja    schedule 16.11.2016