7

In Praat, I want to select a portion of the sound, extract it, and save it separately from the original file. This part of the sound is always between 0.108 s and 0.112 s because it is from pure tones. Here is the code:

Read from file: "sound.wav"
selectObject: "Sound sound"
Select: 0.108, 0.112
Extract selected sound (preserve times)
selectObject: "Sound untitled"
Rename: "new sound"

Every time I run this, I get the error that "Select" (what I use to select from 0.108 to 0.112) is not an option for this object. The error box reads:

Command "Select:" not available for current selection.  Script line 14 not performed or completed: Select: 0.108, 0.112.  

What can I do to make this error go away?

1
  • In the first two solutions proposed in this post it seems to me that variable names cannot be used in the lines editor Sound sound, or editor: sound I tried out a number of syntactic variants none of which worked. The third script above based on 'Extract part' does solve this problem as 'selectObject' can take string variables. (Am I missing something? Thanks!!) – Zoltan Jakab Jun 13 '18 at 14:55
3

You need to switch the "focus" of the commands to the editor. The way it's written now, it's trying to apply the "Select" command to the object in the object window.

Try:

Read from file: "sound.wav"
selectObject: "Sound sound"
Edit
editor Sound sound
    Select: 0.108, 0.112
    Extract selected sound (preserve times)
endeditor
selectObject: "Sound untitled"
Rename: "new sound"

NOTE: In the latest version of Praat for Windows (5.4.12), extracted sounds are automatically named "Sound untitled", hence the penultimate line. You might want to check in your version what the default name is for an extracted sound.

EDIT: Following @jja's suggestion, here is a revised version that uses an object ID to refer to the sound (I also replaced 'endeditor' with 'Close' so that it actually closes the editor window, and I dispensed with the selectObject command because I realized that the extracted sound object will already be selected):

sound = Read from file: "sound.wav"
selectObject: sound
Edit
editor: sound
    Select: 0.108, 0.112
    Extract selected sound (preserve times)
Close
Rename: "new sound"

As @jja points out, the use of an object ID is more robust because it guarantees that you are selecting the exact sound you read in; with the first method, if you have multiple objects with the same name in the object window you might select the wrong one.

Following @robert's suggestion, here is an alternative that bypasses the editor window (the manual way to access the "Extract part" command is to highlight the sound in the object window and choose Convert > Extract part...):

Read from file: "sound.wav"
selectObject: "Sound sound"
Extract part: 0.108, 0.112, "rectangular", 1, "yes"
selectObject: "Sound sound_part"
Rename: "new sound"
7
  • 3
    Another option: Use the "Extract part..." command from the objects window. – robert Jul 1 '15 at 21:42
  • @musicallinguist -- Good suggestion. I am now receiving the error message: "Unknown variable: editor." – 5823574 Jul 2 '15 at 13:14
  • 1
    Hmm, it's working for me as is (with the correction in the penultimate line, as noted above). What version of Praat are you using? Alternatively you can try the "Extract part" method, which I added per @robert's suggestion. – musicallinguist Jul 2 '15 at 14:32
  • 1
    @5823574 Great! For future reference, you didn't actually need to use the 'at' in front of my username; the comment is under my response and users get notified of any comments that appear under their own questions or responses regardless of whether they are tagged in the comments. – musicallinguist Jul 6 '15 at 15:13
  • 1
    You don't need to know the default name of sounds to use the editor: you can use object ids, which are normally more robust. You can do sound = Read from file... and then editor: sound. View & Edit also returns the id of the object for which the editor is, so you can also do sound = View & Edit if you have a Sound selected (although this doesn't work with editors for more than one object). – jja Jul 16 '15 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.