5 sentence Recorded_audio ookhetweer.wav
6 real Pitch 70 (= Hz, mean)
7 real Pitch_SD 15 (= % of mean)
8 real Duration 1.3 (= mult. factor)
10 real Bubbles 5 (= rate)
11 real Bubbles_SNR 15 (= dB SNR)
14 positive Voicing_floor_(dB) 15 (= below maximum)
18 ########################################################################
20 # VoiceConversion.praat
22 # Change the input speech to resemble Tracheoesophageal speech.
23 # Changes the Pitch (F0) and pitch movements, duration. Filtered noise
24 # is added as well as filtered "bubble" sounds.
25 # Increase the Jitter and Shimmer of a speech recording to the
26 # number given. Cannot reduce Jitter or Shimmer.
27 # Note that Jitter and Shimmer are ill-defined in anything but
30 # Uses the To PointProcess (periodic, cc) to calculate the jitter
31 # and To PointProcess (periodic, peaks): 60, 300, "yes", "yes"
32 # to change the timing of the periods.
34 # Periods are moved with Overlap-and-Add
36 # Shimmer is adapted using additive noise over an intensity tier and
37 # adapting each period individually. Periods are determined with the
38 # To PointProcess (periodic, peaks) pulses.
40 ########################################################################
42 # Copyright (C) 2016-2017 NKI-AVL, R. J. J. H. van Son
45 # This program is free software: you can redistribute it and/or modify
46 # it under the terms of the GNU General Public License as published by
47 # the Free Software Foundation, either version 3 of the License, or
48 # (at your option) any later version.
50 # This program is distributed in the hope that it will be useful,
51 # but WITHOUT ANY WARRANTY; without even the implied warranty of
52 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 # GNU General Public License for more details.
55 # You should have received a copy of the GNU General Public License
56 # along with this program. If not, see <http://www.gnu.org/licenses/>.
58 # Full license text is available at:
59 # http://www.gnu.org/licenses/gpl-3.0.html
61 ########################################################################
63 # Input parameters (<=0 means "do not change"):
65 # Input file A file name (with full path). If a Sound object is selected, that will be used instead
66 # Pitch Average pitch of the new speech in Hz [F'(t) = Fnew/Fold * F(t)]
67 # Pitch SD Standard deviation of the Pitch of the new speech in Hz (compresses pitch movements)
68 # [SD'(t) = SDnew/SDold * (F(t) - Faverage) + Faverage]
69 # Duration Factor with which to multiply the duration
70 # HNR Signal to Noise ratio of new noise added to obtain the HNR given
71 # Bubbles Rate of bubble sounds added (per second). Select random bubbles from bubbles.wav&bubbles.TextGrid
72 # Bubbles SNR Signal to Noise ratio of bubble sounds added (use bubbles.wav)
73 # Jitter New jitter in %
74 # Shimmer New Shimmer in %
75 # Voicing floor Lowest level of sound still considered voiced, in dB below the maximum
77 # Help Print this text and exit
80 # The input sound converted according to the specifications
82 # Print debugging information
87 # A Praat Sound object with the transformed speech
90 # praat VoiceConversion.praat Speech/Example1.wav 70 15 1.3 5 5 15 5 10 15 no
98 printline Input parameters (<=0 means "do not change"):
99 printline Input file'tab$''tab$'A file name (with full path). If a Sound object is selected, that will be used instead
100 printline Pitch'tab$''tab$''tab$'Average pitch of the new speech in Hz [F'(t) = Fnew/Fold * F(t)]
101 printline Pitch SD'tab$''tab$'Standard deviation of the Pitch of the new speech in Hz (compresses pitch movements)
102 printline 'tab$''tab$''tab$''tab$'[SD'(t) = SDnew/SDold * (F(t) - Faverage) + Faverage]
103 printline Duration'tab$''tab$'Factor with which to multiply the duration
104 printline HNR'tab$''tab$''tab$''tab$'Signal to Noise ratio of new noise added to obtain the HNR given
105 printline Bubbles'tab$''tab$''tab$'Rate of bubble sounds added (per second). Select random bubbles from bubbles.wav&bubbles.TextGrid
106 printline Bubbles SNR'tab$''tab$'Signal to Noise ratio of bubble sounds added (use bubbles.wav)
107 printline Jitter'tab$''tab$''tab$'New jitter in %
108 printline Shimmer'tab$''tab$''tab$'New Shimmer in %
109 printline Voicing floor'tab$'Lowest level of sound still considered voiced, in dB below the maximum
111 printline Help'tab$''tab$''tab$'Print this text and exit
114 printline The input sound converted according to the specifications
121 if numberOfSelected("Sound") > 0
122 .recordedSound = selected("Sound")
123 elsif recorded_audio$ <> "" and fileReadable(recorded_audio$)
124 .recordedSound = Read from file: recorded_audio$
125 Rename: "RecordedSpeech"
128 bubblesAudioName$ = "bubbles.wav"
130 .thresshold = -voicing_floor
133 select .recordedSound
134 global.setIntensity = Get intensity (dB)
136 call convert_speechOverlapAndAdd .recordedSound .thresshold jitter shimmer pitch pitch_SD duration hNR bubbles bubbles_SNR
138 # Definitions of functions
141 procedure convert_speechOverlapAndAdd .recordedSound .thresshold .jitter .shimmer .pitch .pitch_SD .durationFactor .newHNR .bubble_rate .bubble_snr
142 call change_pitch_duration .recordedSound .pitch .pitch_SD .durationFactor
143 .newPitchSound = selected("Sound")
145 call extractVoicingParameters .newPitchSound .thresshold
146 .recordedTextGrid = selected("TextGrid")
147 .recordedPulses = selected("PointProcess")
148 .recordedInt = selected("Intensity")
150 select .newPitchSound
151 .recordedPulsesPeaks = To PointProcess (periodic, peaks): 60, 300, "yes", "yes"
153 call create_additive_noise .newPitchSound .newHNR .recordedTextGrid
154 .additiveNoise = selected("Sound")
156 call add_bubbles .newPitchSound .bubble_rate .bubble_snr .recordedTextGrid 'bubblesAudioName$'
157 .additiveBubbles = selected("Sound")
159 # Change Jitter, use CC to determine jitter and Peaks to change the periods
160 selectObject: .recordedPulsesPeaks
161 .newPointProcess = Copy: "New_Pulses"
162 call set_jitter .jitter .newPointProcess .recordedPulses
163 call test_overlap_add .newPitchSound .recordedPulsesPeaks .recordedTextGrid .newPointProcess .shimmer
164 .newSound = selected("Sound")
169 selectObject: .recordedPulses
170 .old_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
171 selectObject: .newPointProcess
172 .newPPjitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
173 selectObject: .recordedSound
175 .old_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
176 .old_shimmer = Get shimmer (local): 0.0001, 0.03, 2
179 selectObject: .newSound
180 .pointP = To PointProcess (periodic, cc): 60, 300
181 .new_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
183 selectObject: .newSound
185 .new_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
186 .new_shimmer = Get shimmer (local): 0.0001, 0.03, 2
188 appendInfoLine: "New Jitter: '.new_jitter:1%' ('.old_jitter:1%' ~> '.newPPjitter:1%')"
189 appendInfoLine: "New Shimmer: '.new_shimmer:1%' ('.old_shimmer:1%')"
191 selectObject: .old_amplitude, .pointP, .new_amplitude
195 # Add noise to result
196 call add_sounds .newSound .additiveNoise
197 .resultNoise = selected("Sound")
200 # Add bubbles to result
201 call add_sounds .resultNoise .additiveBubbles
202 .result = selected("Sound")
206 selectObject: .newPitchSound, .recordedTextGrid, .recordedPulses, .recordedInt, .newPointProcess, .recordedPulsesPeaks, .newSound, .additiveNoise, .additiveBubbles, .resultNoise
209 selectObject: .result
212 procedure change_pitch_duration .sound .pitch .pitchFraction .durationFactor
214 .duration = Get total duration
216 .manipulation = To Manipulation: 0.01, 70, 300
217 .pitchTier = Extract pitch tier
218 .currentPitch = Get mean (points): 0, 0
219 .pitch_SD = .pitchFraction / 100 * .pitch
222 .durationTier = Extract duration tier
225 if .durationFactor > 0
226 .numPoints = Get number of points
230 Formula: "self*'.durationFactor'"
233 Replace duration tier
238 .factor = (.pitch / .currentPitch)
239 Multiply frequencies: 0, .duration, .factor
240 .currentSD = Get standard deviation (points): 0, 0
243 .factor = .pitch_SD / .currentSD
244 Formula: "'.pitch' + (self - '.pitch') * '.factor'"
253 if .currentPitch > 0 or .durationFactor > 0
255 .newSound = Get resynthesis (overlap-add)
258 .newSound = Copy: "New Sound"
268 procedure extractVoicingParameters .recordedSound .thresshold
269 # The lowest level of voiced sounds
270 select .recordedSound
271 .pointPcc = To PointProcess (periodic, cc): 60, 300
272 Rename: "RecordedPulses"
273 .textGrid = To TextGrid (vuv): 0.02, 0.01
274 Rename: "RecordedVoicing"
275 .numIntervals = Get number of intervals: 1
277 # Correct voicing boundaries
278 select .recordedSound
279 .intensity = To Intensity: 100, 0, "yes"
280 Rename: "RecordedIntensity"
281 .silences = To TextGrid (silences): .thresshold, 0.1, 0.05, "silent", "sounding"
284 for .i to .numIntervals
286 .label$ = Get label of interval: 1, .i
288 .start = Get starting point: 1, .i
289 .end = Get end point: 1, .i
291 # Starting point of voiced interval
293 .s = Get interval at time: 1, .start
294 .sLabel$ = Get label of interval: 1, .s
295 if .sLabel$ = "silent"
296 .sStart = Get starting point: 1, .s
297 .sEnd = Get end point: 1, .s
300 Set interval text: 1, .i, "U"
301 # Shift boundaries: Insert&Remove
302 Insert boundary: 1, .sEnd
303 Set interval text: 1, .i+1, "V"
305 Set interval text: 1, .i, ""
306 Remove left boundary: 1, .i
309 # Low intensity, unvoiced
310 Set interval text: 1, .i, "U"
317 for .i to .numIntervals
319 .label$ = Get label of interval: 1, .i
321 .start = Get starting point: 1, .i
322 .end = Get end point: 1, .i
324 # Starting point of voiced interval
326 .s = Get interval at time: 1, .end
327 .sLabel$ = Get label of interval: 1, .s
328 if .sLabel$ = "silent"
329 .sStart = Get starting point: 1, .s
330 .sEnd = Get end point: 1, .s
333 Set interval text: 1, .i, "U"
334 # Shift boundaries: Insert&Remove
335 Insert boundary: 1, .sStart
336 Set interval text: 1, .i, "V"
338 Set interval text: 1, .i+1, ""
339 Remove right boundary: 1, .i+1
342 # Low intensity, unvoiced
343 Set interval text: 1, .i, "U"
357 procedure create_additive_noise .sound .newHNR .vuvTextGrid
359 .duration = Get total duration
360 .sampleFreq = Get sampling frequency
362 .additiveNoiseSound = -1
364 # Determine noise level
366 .originalIntensity = Get intensity (dB)
367 .additiveNoise = .originalIntensity - .newHNR
371 .downsampled = Resample: 10000, 50
372 .lpc = To LPC (autocorrelation): 10, 0.025, 0.005, 50
374 .source = Filter (inverse)
375 .sourceInt = To Intensity: 70, 0, "yes"
376 .sourceIntTier = To IntensityTier (peaks)
378 # Create additive noise
379 if .additiveNoise > 0
380 .noise = Create Sound from formula: "WhiteNoise", 1, 0, .duration, .sampleFreq, "randomGauss(0,0.1)"
382 .filteredNoise = Filter: "no"
384 .additiveNoiseSoundTMP = Multiply: "yes"
385 call set_VUV_to_zero .additiveNoiseSoundTMP .vuvTextGrid U
386 Scale intensity: .additiveNoise
387 .additiveNoiseSound = Resample: .sampleFreq, 50
389 selectObject: .noise, .filteredNoise, .additiveNoiseSoundTMP
393 selectObject: .downsampled, .lpc, .source, .sourceInt, .sourceIntTier
398 if .additiveNoiseSound <= 0
399 .additiveNoiseSound = Create Sound from formula: "AdditiveNoise", 1, 0, .duration, .sampleFreq, "0"
402 select .additiveNoiseSound
405 procedure add_sounds .sound1 .sound2
406 selectObject: .sound1, .sound2
407 .stereo = Combine to stereo
408 .addedSound = Convert to mono
413 selectObject: .addedSound
417 # Set Jitter to a specified number
419 # Ti = ti - ti-1 (interval i)
420 # Jitter (absolute) is Sum[ abs(Ti - Ti-1) ] / N-1
421 # Jitter = Jitter (absolute) / mean(Ti)
423 # For a Normal distribution
424 # E(|X|) = sqrt(2/pi) * stdev(X)
427 # E(Ti^2) = var(Ti) + E(Ti)^2
428 # E(Ti*Ti-1) = cor(Ti, Ti-1) + E(Ti)^2
429 # var(Ti - Ti-1) = E(Ti^2 - 2*Ti*Ti-1 + Ti-1^2)
430 # = 2*E(Ti^2) - 2*E(Ti*Ti-1)
431 # = 2*[ var(Ti) * (1 - cor(Ti, Ti-1)) ]
433 # Combine, assuming a Normal distribution:
434 # Jitter = E(|Ti - Ti-1|) / E(Ti)
435 # = sqrt(2/pi) * stdev(Ti - Ti-1) / mean(Ti)
436 # = sqrt(2/pi * var(Ti - Ti-1)) / mean(Ti)
437 # = sqrt[ 4/pi * ( var(Ti) * (1 - cor(Ti, Ti-1)) ) ] / mean(Ti)
439 # Change Ti -> T'i; Jitter -> a*Jitter while keeping mean(Ti) = mean(T'i) constant
440 # ei = (ti + ti-2)/2 - ti-1
441 # Jitter' = a * Jitter
442 # = a * sqrt[ 4/pi * var(Ti - Ti-1) ] / mean(Ti)
444 # => var(T'i - T'i-1) = a^2 * var(Ti - Ti-1)
445 # = a^2 * E[ (Ti - Ti-1)^2 ]
446 # = a^2 * E[ (ti - ti-1 - ti-1 + ti-2)^2 ]
447 # = a^2 * 2 * E[ ((ti + ti-2)/2 - ti-1)^2 ]
448 # = a^2 * 2 * E[ ei^2 ]
449 # = 2 * E[ (a*ei)^2 ]
452 # Generalizing, var(T'i - T'i-1) = 2*(var(ti-1) + var(ti) + var(ti+1))
453 # To increase Jitter -> Jitter'
454 # 1) Determine var(Ti - Ti-1) = (Jitter * mean(Ti))^2 * pi / 2
455 # 2) Calculate var(T'i - T'i-1) = (Jitter' * mean(T'i))^2 * pi / 2
456 # 3) Determine var to add:
457 # add_var(Ti - Ti-1) = var(T'i - T'i-1) - var(Ti - Ti-1)
458 # 4) Var of Noise to add per ti: add_var(ti) = add_var(Ti - Ti-1)/(2*3)
459 # 5) Sd of Noise to add per ti: add_sd(ti) = sqrt(add_var(ti))
462 # Converts .pulses into pulses with new Jitter
463 procedure set_jitter .newJitter .pulses .pulsesCC
465 if .pulses > 0 and .newJitter > 0
468 # Use CC to determine real jitter
472 .current_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
473 .current_abs_jitter = Get jitter (local, absolute): 0, 0, 0.0001, 0.03, 2
474 .current_mean_period = Get mean period: 0, 0, 0.0001, 0.03, 2
475 .current_stdev_period = Get stdev period: 0, 0, 0.0001, 0.03, 2
477 if .newJitter > .current_jitter
478 .current_var = .current_abs_jitter**2 * pi/2
479 .end_var = (.newJitter * .current_mean_period)**2 * pi/2
480 # The variance to add per boundary (total / (2*3))
481 .add_var = (.end_var - .current_var) / 6
482 .stdev_e = sqrt(.add_var)
484 # Keep the original pulses just is case the order of the pulses might change
486 .origPulses = Copy: "Original_Pulses"
487 .numPoints = Get number of points
490 # Change jitter by moving the ti according to
491 # t'i = ti - randomGauss(0, stdev(e'))
492 for .p from 1 to .numPoints
494 .t = Get time from index: .p
495 .new_t = .t - randomGauss(0, .stdev_e)
497 # Remove current point
499 .r = Get nearest index: .t
507 pause New jitter: '.newJitter' must be larger than current jitter '.current_jitter:4'
510 # Calculate new jitter
512 .jitter_new = Get jitter (local): 0, 0, 0.0001, 0.03, 2
514 .current_jitter *= 100
521 # We cannot use the shimmer of a sentence, so we can only "add" shimmer
523 # .new_shimmer is in %
524 # .sound: Source Sound
525 # .pulses: PointProcess
526 # .voicing: VUV TextGrid
527 # .new_shimmer: New shimmer in %
528 procedure increase_shimmer .sound .pulses .voicing .newShimmer
533 # Create Amplitude Tier and get current shimmer
535 .duration = Get total duration
537 .current_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
538 .current_shimmer = Get shimmer (local): 0.0001, 0.03, 2
539 select .current_amplitude
540 .numPoints = Get number of points
541 .ampreal = Down to TableOfReal
544 for .p from 1 to .numPoints
546 .tmp = Get value: .p, 2
552 .meanAmp = .sumamp / .n
554 # Sd must be multiplied with the amplitude
555 if .newShimmer > .current_shimmer
556 .new_var = (.newShimmer**2 - .current_shimmer**2) * .meanAmp**2 * pi / 2
558 .new_var = .newShimmer**2 * .meanAmp**2 * pi / 2
561 .new_sd = sqrt(.new_var / 2)
566 .new_amplitude = Create AmplitudeTier: "New_Amplitude", 0, .duration
567 for .p from 1 to .numPoints
569 .t = Get value: .p, 1
570 .a = Get value: .p, 2
575 .new_a = .a - randomGauss(0, .new_sd)
581 select .new_amplitude
582 Add point: .t, .new_a / .a
588 # Set unvoiced parts to 1
589 select .new_amplitude
593 .numIntervals = Get number of intervals: 1
594 for .i from 1 to .numIntervals
596 .t = Get end point: 1, .i
597 select .new_amplitude
602 plus .current_amplitude
605 # Overlay shimmer over sound
608 .new_sound = Multiply
609 Rename: "NewSound_Shimmer"
613 .shimmer_new = Get shimmer (local): 0, 0, 0.0001, 0.02, 1.3, 1.6
615 .current_shimmer *= 100
618 select .new_amplitude
623 .new_sound = Copy: "NewSound_Shimmer"
629 # Make a copy of the source to the target matching the pulses in source and target
630 # Copies fragments around pulses in sourcePulses under the direction of the
631 # corresponding pulses in targetPulses using the Overlap&Add method (Gaussian window)
633 # Ignores voiceless parts, ie, intervals between pulses > .maxInt
634 # For voices, .maxInt should be ~0.02 (F0 > 50Hz). For other sounds, e.g., bubbles, this
635 # should be increased to fit the whole sound between pulses.
637 # Midpoint between the pulses, periods add up to a factor of ~1.04.
638 # At the pulses themselves, it adds up to ~1.12 (summed left and right)
640 procedure overlap_add .sourceSound .sourcePulses .targetSound .targetPulses .maxInt
641 # Maximum interval between pulses (maximum pitch period)
647 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
649 .targetName$ = replace_regex$(selected$(), " ", "_", 0)
651 # Iterate over target pulses
653 .numPulses = Get number of points
657 .tTarget = Get time from index: .p
658 .pLeft = Get interval: .tTarget - 0.001
659 .pRight = Get interval: .tTarget + 0.001
662 .q = Get nearest index: .tTarget
663 .tSource = Get time from index: .q
664 .qLeft = Get interval: .tSource - 0.001
665 .qRight = Get interval: .tSource + 0.001
666 # Gaussian window parameters (FWHM Left and Right)
667 # FWHM = 2*sqrt(2*ln(2)) * c
668 .cL = min(.pLeft,.qLeft)/(2*sqrt(2*ln(2)))
669 .cR = min(.pRight,.qRight)/(2*sqrt(2*ln(2)))
670 if not( .cL = undefined or .cL > .maxInt/(2*sqrt(2*ln(2))) or .cR = undefined or .cR > .maxInt/(2*sqrt(2*ln(2))) )
673 Formula (part): .tTarget-.margin, .tTarget+.margin, 1, 1, "if x<.tTarget then self + '.sourceName$'((x - .tTarget) + .tSource)*exp(-1*(((x - .tTarget)/.cL)^2)/2) else self + '.sourceName$'((x - .tTarget) + .tSource)*exp(-1*(((x - .tTarget)/.cR)^2)/2) endif"
680 procedure test_overlap_add .sourceAudio .sourcePulses .vuvTextGrid .targetPulses .newShimmer
681 # Use overlap-add to add new source intervals
682 # Copy only voiced pulses
683 call set_VUV_to_zero .targetPulses .vuvTextGrid U
684 # Create a copy of the old source with voiced parts zeroed
686 .testSource = Copy: "OaAsound"
687 call set_VUV_to_zero .testSource .vuvTextGrid V
689 # Copy the voiced parts of the new source to the zeroed voiced parts of the old source
690 call overlap_add .sourceAudio .sourcePulses .testSource .targetPulses 0.02
691 call increase_shimmer .testSource .targetPulses .vuvTextGrid .newShimmer
692 .newSound = selected("Sound")
693 Scale intensity: global.setIntensity
702 # Set intervals matching a label text to Zero or remove the pulses
703 # Works on Sound and Pulses
704 procedure set_VUV_to_zero .sound .vuvTextGrid .zeroLabel$
706 .objectType$ = selected$()
707 .objectType$ = extractWord$ (.objectType$, "")
709 .numIntervals = Get number of intervals: 1
710 # Zero out VU intervals
711 for .i to .numIntervals
713 .vuvLabel$ = Get label of interval: 1, .i
714 .start = Get starting point: 1, .i
715 .end = Get end point: 1, .i
716 if .vuvLabel$ = .zeroLabel$
718 if .objectType$ = "Sound"
719 Set part to zero: .start, .end, "at nearest zero crossing"
720 elsif .objectType$ = "PointProcess"
721 Remove points between: .start, .end
723 printline Unsupported object type for set_VUV_to_zero
736 # Select a random puls in the bubbles and add it to a random puls in the target
738 # Creates a sound with only the bubbles
740 procedure add_bubbles .sound .rate .snr .vuvTextGrid .bubblesAudioName$
743 .targetIntensity = Get intensity (dB)
744 .targetDuration = Get total duration
745 .tagetSamplingFrequency = Get sampling frequency
746 .targetNumBubbles = .rate * .targetDuration
747 .downsampled = Resample: 10000, 50
748 .lpc = To LPC (autocorrelation): 10, 0.025, 0.005, 50
750 .source = Filter (inverse)
751 .sourceInt = To Intensity: 70, 0, "yes"
752 .sourceIntTier = To IntensityTier (peaks)
759 .additiveBubblesSound = Create Sound: "Bubbles", 0, .targetDuration, .tagetSamplingFrequency, "0"
763 # Create an empty sound to receive the bubbles
764 .bubblesAudio = Read from file: .bubblesAudioName$
765 .bubblesTextGridName$ = replace_regex$(.bubblesAudioName$, "\.[a-z0-9]{2,}$", ".TextGrid", 0)
766 .bubblesTextGrid = Read from file: .bubblesTextGridName$
768 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
769 .bubblesSamplingFrequency = Get sampling frequency
770 .bubblesIntensity = Get intensity (dB)
771 .bubbleSound = Create Sound: "Bubbles", 0, .targetDuration, .bubblesSamplingFrequency, "0"
773 # Fill the new Bubbles
774 select .bubblesTextGrid
775 .numIntervals = Get number of intervals: 1
777 while .bubblesFound < .targetNumBubbles
778 .i = randomInteger(1, .numIntervals)
779 select .bubblesTextGrid
780 .label$ = Get label of interval: 1, .i
781 if .label$ = "sounding"
783 .startPoint = Get starting point: 1, .i
784 .endPoint = Get end point: 1, .i
785 .midPoint = (.startPoint + .endPoint)/2
786 .bubbleDuration = .endPoint - .startPoint
788 # Get random insertion point
789 .t = randomUniform (0.001, .targetDuration-0.001)
790 .targetStart = .t - .bubbleDuration/2
791 .targetEnd = .t + .bubbleDuration/2
793 Formula (part): .targetStart, .targetEnd, 1, 1, "self + '.sourceName$'((x - .t) + .midPoint)"
797 # Convert selected bubbles to scaled source
799 .resampledBubbleSound = Resample: .tagetSamplingFrequency, 50
801 .scaledBubbleSource = Multiply: "yes"
802 call set_VUV_to_zero .scaledBubbleSource .vuvTextGrid U
804 # The measured Intensity of the few selected bubbles can be too low. Correct for scaling
805 select .scaledBubbleSource
806 .bubbleSoundIntensity = Get intensity (dB)
807 .attenuation = .bubblesIntensity - .bubbleSoundIntensity
808 if .attenuation = undefined
812 # Scale bubble sounds
813 select .scaledBubbleSource
814 Scale intensity: .targetIntensity - .snr - .attenuation
816 select .scaledBubbleSource
818 .filteredBubbles = Filter: "no"
819 Rename: "FilteredBubbleNoise"
820 .additiveBubblesSound = Resample: .tagetSamplingFrequency, 50
823 select .resampledBubbleSound
824 plus .scaledBubbleSource
825 plus .filteredBubbles
829 plus .bubblesTextGrid
835 select .additiveBubblesSound
838 procedure add_single_bubble .sourceAudio .sourcePulses .sourceI .targetAudio .targetPulses .targetI
841 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
843 .targetName$ = replace_regex$(selected$(), " ", "_", 0)
847 .tTarget = Get time from index: .targetI
848 .pLeft = Get interval: .tTarget - 0.001
849 .pRight = Get interval: .tTarget + 0.001
853 .tSource = Get time from index: .sourceI
854 .qLeft = Get interval: .tSource - 0.001
855 .qRight = Get interval: .tSource + 0.001
857 # Gaussian window parameters (FWHM Left and Right)
858 # FWHM = 2*sqrt(2*ln(2)) * c
859 .c = (.qLeft+.qRight)/(2*sqrt(2*ln(2)))
860 if not( .cL = undefined or .cR = undefined)
863 Formula (part): .tTarget-.margin, .tTarget+.margin, 1, 1, "self + '.sourceName$'((x - .tTarget) + .tSource)*exp(-1*(((x - .tTarget)/.c)^2)/2)"