2

I want to modify the pitch at two different parts of a wav file. To do that , i have the information of starting time and ending time from the corresponding textgrid file of the wav file. Is it possible to modify the pitch at two parts.

U-571
  • 519
  • 2
  • 7
  • 23

1 Answers1

3

You can use a Manipulation object to make any changes you want to the original sound's pitch.

# Original sound made of three consecutive notes
snd[1] = Create Sound as pure tone: "A", 1, 0, 0.3, 44100, 220, 0.2, 0.01, 0.01
snd[2] = Create Sound as pure tone: "B", 1, 0, 0.3, 44100, 247, 0.2, 0.01, 0.01
snd[3] = Create Sound as pure tone: "C", 1, 0, 0.3, 44100, 277, 0.2, 0.01, 0.01

selectObject(snd[1], snd[2], snd[3])
sound = Concatenate
Rename: "original"

removeObject(snd[1], snd[2], snd[3])

selectObject(sound)
Play

# We will invert the pitch, so that the notes play in the opposite direction
manipulation = To Manipulation: 0.01, 200, 300
pitchtier = Extract pitch tier

# We copy it because we want to modify it, not create one from scratch
# and we want to be able to read the values of the original from somewhere
original = Copy: "old"
points = Get number of points

# This for loop looks at the values of the original pitch tier and writes them
# onto the new pitch tier
for p to points
  selectObject(original)
  f = Get value at index: points - p + 1
  t = Get time from index: p
# If you uncomment the if block, the changes will only affect the first and last
# quarter of the sound
#  if t < 0.25 or t > 0.75
    selectObject(pitchtier)
    Remove point: p
    Add point: t, f
#  endif
endfor

# We replace the pitch tier
selectObject(pitchtier, manipulation)
Replace pitch tier

# Resynthesize
selectObject(manipulation)
new_sound = Get resynthesis (overlap-add)

# And clean up
removeObject(original, pitchtier, manipulation)
selectObject(new_sound)
Rename: "modified"
Play 

You change the pitch tier by adding points at different times with different pitch values (in Hertz), and when you do the resynthesis Praat will modify the original values so they match the ones you specified.

In your case, you can use the time values from the TextGrid to know when the modified PitchTier points need to be added and leave the rest alone. You can also manipulate duration like this.

In the example, the script changes the value of each of the points in the original pitch tier with the value of the points in the inverted order, so that the first point will have the value of the last one. The if block inside the for is one way of limiting those changes to a subset of the pitch tier, but how you do this will depend on the sort of changes you are trying to make.

jja
  • 2,058
  • 14
  • 27
  • Yes, This way i am doing it. The way i am doing it as follows say: in a wav file 3 parts are there ----1----2---3--- and i want to modify 1 and 3 without modifying the 2. For each part say 1, I am extracting pitchtier and modifying it and replacing the previous pitchtier with the new one. Similarly i am doing it for part 3 also. But my question is that can i simultaneously modify the two parts. – U-571 Feb 20 '14 at 04:57
  • I don't understand. Are the three parts separate Sounds? Or are they different parts of a single object (beginning, middle and end, say)? And what do you mean by "simultaneously"? – jja Feb 22 '14 at 23:28
  • No,the three parts belongs to same wav file. yes! they are different parts of single object. so,for doing pitch modification. Each time i have to extract separate pitchtier and keep on replacing them with the original. Is this the robust way of doing it. – U-571 Feb 24 '14 at 04:04
  • 1
    You don't need to extract the pitch tier once for each part. Doing so can be preferable depending on what change you want to make, but you could extract it once, make the changes on the parts that you are interested in changing, and then apply the changes all at once with the Manipulation object. I edited my answer to give an example of this, but the exact process will depend on what you are doing. – jja Feb 25 '14 at 04:52
  • Can the same technique be used for the Intensity modification also ! – U-571 Feb 25 '14 at 05:20
  • No. Manipulation objects only modify pitch and duration. If you want to manipulate intensity as well I suggest you look at the [documentation](http://www.fon.hum.uva.nl/praat/manual/Intro_8_3__Manipulation_of_intensity.html) – jja Feb 25 '14 at 06:26