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 1 (= fraction)
11 real Bubbles_SNR 10 (= 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 Fraction of time bubble sounds are the source (0-1, 0 = disable). Use source "TE_source_bubbles.wav"
72 # Bubbles SNR Signal to Noise ratio of bubble source (in dB)
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$'Fraction of time bubble sounds are the source (0-1, 0 = disable). Use source "TE_source_bubbles.wav"
106 printline Bubbles SNR'tab$''tab$'Signal to Noise ratio of bubble sounds added (in dB)
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 te_source_bubbles_name$ = "TE_source_bubbles.wav"
132 .thresshold = -voicing_floor
135 select .recordedSound
136 global.setIntensity = Get intensity (dB)
138 call convert_speechOverlapAndAdd .recordedSound .thresshold jitter shimmer pitch pitch_SD duration hNR bubbles bubbles_SNR
140 # Definitions of functions
143 procedure convert_speechOverlapAndAdd .recordedSound .thresshold .jitter .shimmer .pitch .pitch_SD .durationFactor .newHNR .bubble_fraction .bubble_snr
144 call change_pitch_duration .recordedSound .pitch .pitch_SD .durationFactor
145 .newPitchSound = selected("Sound")
147 call extractVoicingParameters .newPitchSound .thresshold
148 .recordedTextGrid = selected("TextGrid")
149 .recordedPulses = selected("PointProcess")
150 .recordedInt = selected("Intensity")
152 select .newPitchSound
153 .recordedPulsesPeaks = To PointProcess (periodic, peaks): 60, 300, "yes", "yes"
156 call create_additive_noise .newPitchSound .recordedTextGrid
157 .additiveNoise = selected("Sound")
162 #call add_bubbles '.newPitchSound' '.bubble_fraction' '.bubble_snr' '.recordedTextGrid' 'bubblesAudioName$'
163 #.additiveBubbles = selected("Sound")
165 # Change Jitter, use CC to determine jitter and Peaks to change the periods
166 selectObject: .recordedPulsesPeaks
167 .newPointProcess = Copy: "New_Pulses"
168 call set_jitter .jitter .newPointProcess .recordedPulses
169 call test_overlap_add .newPitchSound .recordedPulsesPeaks .recordedTextGrid .newPointProcess .shimmer
170 .newSound = selected("Sound")
172 # Create bubbles from source
173 call add_source_bubbles '.newPitchSound' '.recordedPulses' 0.7 10 'te_source_bubbles_name$'
174 .additiveBubbles = selected("Sound")
179 selectObject: .recordedPulses
180 .old_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
181 selectObject: .newPointProcess
182 .newPPjitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
183 selectObject: .recordedSound
185 .old_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
186 .old_shimmer = Get shimmer (local): 0.0001, 0.03, 2
189 selectObject: .newSound
190 .pointP = To PointProcess (periodic, cc): 60, 300
191 .new_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
193 selectObject: .newSound
195 .new_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
196 .new_shimmer = Get shimmer (local): 0.0001, 0.03, 2
198 appendInfoLine: "New Jitter: '.new_jitter:1%' ('.old_jitter:1%' ~> '.newPPjitter:1%')"
199 appendInfoLine: "New Shimmer: '.new_shimmer:1%' ('.old_shimmer:1%')"
201 selectObject: .old_amplitude, .pointP, .new_amplitude
205 # Add noise to result
206 call add_sounds .newSound .additiveNoise .newHNR
207 .resultNoise = selected("Sound")
210 # Add bubbles to result
211 call add_sounds .resultNoise .additiveBubbles .bubble_snr
212 .result = selected("Sound")
216 selectObject: .newPitchSound, .recordedTextGrid, .recordedPulses, .recordedInt, .newPointProcess, .recordedPulsesPeaks, .newSound, .additiveNoise, .additiveBubbles, .resultNoise
219 selectObject: .result
223 procedure change_pitch_duration .sound .pitch .pitchFraction .durationFactor
225 .duration = Get total duration
227 .manipulation = To Manipulation: 0.01, 70, 300
228 .pitchTier = Extract pitch tier
229 .currentPitch = Get mean (points): 0, 0
230 .pitch_SD = .pitchFraction / 100 * .pitch
233 .durationTier = Extract duration tier
236 if .durationFactor > 0
237 .numPoints = Get number of points
241 Formula: "self*'.durationFactor'"
244 Replace duration tier
249 .factor = (.pitch / .currentPitch)
250 Multiply frequencies: 0, .duration, .factor
251 .currentSD = Get standard deviation (points): 0, 0
254 .factor = .pitch_SD / .currentSD
255 Formula: "'.pitch' + (self - '.pitch') * '.factor'"
264 if .currentPitch > 0 or .durationFactor > 0
266 .newSound = Get resynthesis (overlap-add)
269 .newSound = Copy: "New Sound"
279 procedure extractVoicingParameters .recordedSound .thresshold
280 # The lowest level of voiced sounds
281 select .recordedSound
282 .pointPcc = To PointProcess (periodic, cc): 60, 300
283 Rename: "RecordedPulses"
284 .textGrid = To TextGrid (vuv): 0.02, 0.01
285 Rename: "RecordedVoicing"
286 .numIntervals = Get number of intervals: 1
288 # Correct voicing boundaries
289 select .recordedSound
290 .intensity = To Intensity: 100, 0, "yes"
291 Rename: "RecordedIntensity"
292 .silences = To TextGrid (silences): .thresshold, 0.1, 0.05, "silent", "sounding"
295 for .i to .numIntervals
297 .label$ = Get label of interval: 1, .i
299 .start = Get starting point: 1, .i
300 .end = Get end point: 1, .i
302 # Starting point of voiced interval
304 .s = Get interval at time: 1, .start
305 .sLabel$ = Get label of interval: 1, .s
306 if .sLabel$ = "silent"
307 .sStart = Get starting point: 1, .s
308 .sEnd = Get end point: 1, .s
311 Set interval text: 1, .i, "U"
312 # Shift boundaries: Insert&Remove
313 Insert boundary: 1, .sEnd
314 Set interval text: 1, .i+1, "V"
316 Set interval text: 1, .i, ""
317 Remove left boundary: 1, .i
320 # Low intensity, unvoiced
321 Set interval text: 1, .i, "U"
328 for .i to .numIntervals
330 .label$ = Get label of interval: 1, .i
332 .start = Get starting point: 1, .i
333 .end = Get end point: 1, .i
335 # Starting point of voiced interval
337 .s = Get interval at time: 1, .end
338 .sLabel$ = Get label of interval: 1, .s
339 if .sLabel$ = "silent"
340 .sStart = Get starting point: 1, .s
341 .sEnd = Get end point: 1, .s
344 Set interval text: 1, .i, "U"
345 # Shift boundaries: Insert&Remove
346 Insert boundary: 1, .sStart
347 Set interval text: 1, .i, "V"
349 Set interval text: 1, .i+1, ""
350 Remove right boundary: 1, .i+1
353 # Low intensity, unvoiced
354 Set interval text: 1, .i, "U"
368 procedure create_additive_noise .sound .vuvTextGrid
370 .duration = Get total duration
371 .sampleFreq = Get sampling frequency
373 .additiveNoiseSound = -1
377 .downsampled = Resample: 10000, 50
378 .lpc = To LPC (autocorrelation): 10, 0.025, 0.005, 50
380 .source = Filter (inverse)
381 .sourceInt = To Intensity: 70, 0, "yes"
382 .sourceIntTier = To IntensityTier (peaks)
384 # Create additive noise
385 .noise = Create Sound from formula: "WhiteNoise", 1, 0, .duration, .sampleFreq, "randomGauss(0,0.1)"
387 .filteredNoise = Filter: "no"
389 .additiveNoiseSoundTMP = Multiply: "yes"
390 call set_VUV_to_zero .additiveNoiseSoundTMP .vuvTextGrid U
391 .additiveNoiseSound = Resample: .sampleFreq, 50
393 selectObject: .noise, .filteredNoise, .additiveNoiseSoundTMP
396 selectObject: .downsampled, .lpc, .source, .sourceInt, .sourceIntTier
399 if .additiveNoiseSound <= 0
400 .additiveNoiseSound = Create Sound from formula: "AdditiveNoise", 1, 0, .duration, .sampleFreq, "0"
403 select .additiveNoiseSound
406 procedure add_sounds .sound1 .sound2 .s1_s2ratioDB
411 .tmp1 = Copy: "Sound1"
412 .int1 = Get intensity (dB)
413 .duration = Get total duration
414 .sampleFreq = Get sampling frequency
419 .tmp2 = Copy: "Sound2"
420 .int2 = Get intensity (dB)
421 .duration = Get total duration
422 .sampleFreq = Get sampling frequency
426 .tmp1 = Create Sound from formula: "BubblesNoise1", 1, 0, .duration, .sampleFreq, "0"
428 .tmp2 = Create Sound from formula: "BubblesNoise2", 1, 0, .duration, .sampleFreq, "0"
431 if .int1 - .int2 <> .s1_s2ratioDB
432 .ratio = .s1_s2ratioDB - (.int1 - .int2)
434 Scale intensity: .int1 + .ratio / 2
436 Scale intensity: .int2 - .ratio / 2
438 selectObject: .tmp1, .tmp2
439 .stereo = Combine to stereo
440 .addedSound = Convert to mono
442 selectObject: .stereo, .tmp1, .tmp2
445 selectObject: .addedSound
449 # Set Jitter to a specified number
451 # Ti = ti - ti-1 (interval i)
452 # Jitter (absolute) is Sum[ abs(Ti - Ti-1) ] / N-1
453 # Jitter = Jitter (absolute) / mean(Ti)
455 # For a Normal distribution
456 # E(|X|) = sqrt(2/pi) * stdev(X)
459 # E(Ti^2) = var(Ti) + E(Ti)^2
460 # E(Ti*Ti-1) = cor(Ti, Ti-1) + E(Ti)^2
461 # var(Ti - Ti-1) = E(Ti^2 - 2*Ti*Ti-1 + Ti-1^2)
462 # = 2*E(Ti^2) - 2*E(Ti*Ti-1)
463 # = 2*[ var(Ti) * (1 - cor(Ti, Ti-1)) ]
465 # Combine, assuming a Normal distribution:
466 # Jitter = E(|Ti - Ti-1|) / E(Ti)
467 # = sqrt(2/pi) * stdev(Ti - Ti-1) / mean(Ti)
468 # = sqrt(2/pi * var(Ti - Ti-1)) / mean(Ti)
469 # = sqrt[ 4/pi * ( var(Ti) * (1 - cor(Ti, Ti-1)) ) ] / mean(Ti)
471 # Change Ti -> T'i; Jitter -> a*Jitter while keeping mean(Ti) = mean(T'i) constant
472 # ei = (ti + ti-2)/2 - ti-1
473 # Jitter' = a * Jitter
474 # = a * sqrt[ 4/pi * var(Ti - Ti-1) ] / mean(Ti)
476 # => var(T'i - T'i-1) = a^2 * var(Ti - Ti-1)
477 # = a^2 * E[ (Ti - Ti-1)^2 ]
478 # = a^2 * E[ (ti - ti-1 - ti-1 + ti-2)^2 ]
479 # = a^2 * 2 * E[ ((ti + ti-2)/2 - ti-1)^2 ]
480 # = a^2 * 2 * E[ ei^2 ]
481 # = 2 * E[ (a*ei)^2 ]
484 # Generalizing, var(T'i - T'i-1) = 2*(var(ti-1) + var(ti) + var(ti+1))
485 # To increase Jitter -> Jitter'
486 # 1) Determine var(Ti - Ti-1) = (Jitter * mean(Ti))^2 * pi / 2
487 # 2) Calculate var(T'i - T'i-1) = (Jitter' * mean(T'i))^2 * pi / 2
488 # 3) Determine var to add:
489 # add_var(Ti - Ti-1) = var(T'i - T'i-1) - var(Ti - Ti-1)
490 # 4) Var of Noise to add per ti: add_var(ti) = add_var(Ti - Ti-1)/(2*3)
491 # 5) Sd of Noise to add per ti: add_sd(ti) = sqrt(add_var(ti))
494 # Converts .pulses into pulses with new Jitter
495 procedure set_jitter .newJitter .pulses .pulsesCC
497 if .pulses > 0 and .newJitter > 0
500 # Use CC to determine real jitter
504 .current_jitter = Get jitter (local): 0, 0, 0.0001, 0.03, 2
505 .current_abs_jitter = Get jitter (local, absolute): 0, 0, 0.0001, 0.03, 2
506 .current_mean_period = Get mean period: 0, 0, 0.0001, 0.03, 2
507 .current_stdev_period = Get stdev period: 0, 0, 0.0001, 0.03, 2
509 if .newJitter > .current_jitter
510 .current_var = .current_abs_jitter**2 * pi/2
511 .end_var = (.newJitter * .current_mean_period)**2 * pi/2
512 # The variance to add per boundary (total / (2*3))
513 .add_var = (.end_var - .current_var) / 6
514 .stdev_e = sqrt(.add_var)
516 # Keep the original pulses just is case the order of the pulses might change
518 .origPulses = Copy: "Original_Pulses"
519 .numPoints = Get number of points
522 # Change jitter by moving the ti according to
523 # t'i = ti - randomGauss(0, stdev(e'))
524 for .p from 1 to .numPoints
526 .t = Get time from index: .p
527 .new_t = .t - randomGauss(0, .stdev_e)
529 # Remove current point
531 .r = Get nearest index: .t
539 pause New jitter: '.newJitter' must be larger than current jitter '.current_jitter:4'
542 # Calculate new jitter
544 .jitter_new = Get jitter (local): 0, 0, 0.0001, 0.03, 2
546 .current_jitter *= 100
553 # We cannot use the shimmer of a sentence, so we can only "add" shimmer
555 # .new_shimmer is in %
556 # .sound: Source Sound
557 # .pulses: PointProcess
558 # .voicing: VUV TextGrid
559 # .new_shimmer: New shimmer in %
560 procedure increase_shimmer .sound .pulses .voicing .newShimmer
565 # Create Amplitude Tier and get current shimmer
567 .duration = Get total duration
569 .current_amplitude = To AmplitudeTier (period): 0, 0, 0.0001, 0.03, 2
570 .current_shimmer = Get shimmer (local): 0.0001, 0.03, 2
571 select .current_amplitude
572 .numPoints = Get number of points
573 .ampreal = Down to TableOfReal
576 for .p from 1 to .numPoints
578 .tmp = Get value: .p, 2
584 .meanAmp = .sumamp / .n
586 # Sd must be multiplied with the amplitude
587 if .newShimmer > .current_shimmer
588 .new_var = (.newShimmer**2 - .current_shimmer**2) * .meanAmp**2 * pi / 2
590 .new_var = .newShimmer**2 * .meanAmp**2 * pi / 2
593 .new_sd = sqrt(.new_var / 2)
598 .new_amplitude = Create AmplitudeTier: "New_Amplitude", 0, .duration
599 for .p from 1 to .numPoints
601 .t = Get value: .p, 1
602 .a = Get value: .p, 2
607 .new_a = .a - randomGauss(0, .new_sd)
613 select .new_amplitude
614 Add point: .t, .new_a / .a
620 # Set unvoiced parts to 1
621 select .new_amplitude
625 .numIntervals = Get number of intervals: 1
626 for .i from 1 to .numIntervals
628 .t = Get end point: 1, .i
629 select .new_amplitude
634 plus .current_amplitude
637 # Overlay shimmer over sound
640 .new_sound = Multiply
641 Rename: "NewSound_Shimmer"
645 .shimmer_new = Get shimmer (local): 0, 0, 0.0001, 0.02, 1.3, 1.6
647 .current_shimmer *= 100
650 select .new_amplitude
655 .new_sound = Copy: "NewSound_Shimmer"
661 # Make a copy of the source to the target matching the pulses in source and target
662 # Copies fragments around pulses in sourcePulses under the direction of the
663 # corresponding pulses in targetPulses using the Overlap&Add method (Gaussian window)
665 # Ignores voiceless parts, ie, intervals between pulses > .maxInt
666 # For voices, .maxInt should be ~0.02 (F0 > 50Hz). For other sounds, e.g., bubbles, this
667 # should be increased to fit the whole sound between pulses.
669 # Midpoint between the pulses, periods add up to a factor of ~1.04.
670 # At the pulses themselves, it adds up to ~1.12 (summed left and right)
672 procedure overlap_add .sourceSound .sourcePulses .targetSound .targetPulses .maxInt
673 # Create empty .targetSound if .targetSound does not exist
676 .duration = Get total duration
677 .samplingFrequency = Get sampling frequency
678 .targetSound = Create Sound from formula: "Target Sound", 1, 0, .duration, .samplingFrequency, "0"
680 # Default, just copy the source pulses
681 if .targetPulses <= 0
682 .targetPulses = .sourcePulses
685 # Maximum interval between pulses (maximum pitch period)
691 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
693 .targetName$ = replace_regex$(selected$(), " ", "_", 0)
695 # Iterate over target pulses
697 .numPulses = Get number of points
701 .tTarget = Get time from index: .p
702 .pLeft = Get interval: .tTarget - 0.001
703 .pRight = Get interval: .tTarget + 0.001
706 .q = Get nearest index: .tTarget
707 .tSource = Get time from index: .q
708 .qLeft = Get interval: .tSource - 0.001
709 .qRight = Get interval: .tSource + 0.001
710 # Gaussian window parameters (FWHM Left and Right)
711 # FWHM = 2*sqrt(2*ln(2)) * c
712 .cL = min(.pLeft,.qLeft)/(2*sqrt(2*ln(2)))
713 .cR = min(.pRight,.qRight)/(2*sqrt(2*ln(2)))
714 if not( .cL = undefined or .cL > .maxInt/(2*sqrt(2*ln(2))) or .cR = undefined or .cR > .maxInt/(2*sqrt(2*ln(2))) )
717 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"
725 procedure test_overlap_add .sourceAudio .sourcePulses .vuvTextGrid .targetPulses .newShimmer
726 # Use overlap-add to add new source intervals
727 # Copy only voiced pulses
728 call set_VUV_to_zero .targetPulses .vuvTextGrid U
729 # Create a copy of the old source with voiced parts zeroed
731 .testSource = Copy: "OaAsound"
732 call set_VUV_to_zero .testSource .vuvTextGrid V
734 # Copy the voiced parts of the new source to the zeroed voiced parts of the old source
735 call overlap_add .sourceAudio .sourcePulses .testSource .targetPulses 0.02
736 call increase_shimmer .testSource .targetPulses .vuvTextGrid .newShimmer
737 .newSound = selected("Sound")
738 Scale intensity: global.setIntensity
747 # Set intervals matching a label text to Zero or remove the pulses
748 # Works on Sound and Pulses
749 procedure set_VUV_to_zero .sound .vuvTextGrid .zeroLabel$
751 .objectType$ = selected$()
752 .objectType$ = extractWord$ (.objectType$, "")
754 .numIntervals = Get number of intervals: 1
755 # Zero out VU intervals
756 for .i to .numIntervals
758 .vuvLabel$ = Get label of interval: 1, .i
759 .start = Get starting point: 1, .i
760 .end = Get end point: 1, .i
761 if .vuvLabel$ = .zeroLabel$
763 if .objectType$ = "Sound"
764 Set part to zero: .start, .end, "at nearest zero crossing"
765 elsif .objectType$ = "PointProcess"
766 Remove points between: .start, .end
768 printline Unsupported object type for set_VUV_to_zero
777 # Create a new Bubbles source file from an existing source file
779 # Uses only a randomly selected fraction of the source pulses
781 procedure create_source_bubbles .sourceSound .sourcePulses .fraction
782 # Normalize fraction: <0, 1]. values > 1 are considered %
785 elsif .fraction > 1 and .fraction <= 100
786 .fraction = .fraction / 100
787 elsif .fraction <= 1000
788 .fraction = .fraction / 1000
795 .targetPulses = Copy: "Target Pulses"
797 .numPulses = Get number of points
798 .discard = 1 - .fraction
800 .rand = randomUniform (0, 1)
808 call overlap_add '.sourceSound' '.sourcePulses' -1 '.targetPulses' 0.02
809 .targetSound = overlap_add.targetSound
816 procedure add_source_bubbles .sound .pulses .fraction .snr .bubblesAudioName$
819 .duration = Get total duration
820 .samplingFrequency = Get sampling frequency
827 .targetIntensity = Get intensity (dB)
828 .targetDuration = Get total duration
829 .downsampled = Resample: 10000, 50
830 .lpc = To LPC (autocorrelation): 10, 0.025, 0.005, 50
832 .source = Filter (inverse)
833 .sourceInt = To Intensity: 70, 0, "yes"
834 .sourceIntTier = To IntensityTier (peaks)
840 # Create the taget file
841 .masterSourceSound = Read from file: .bubblesAudioName$
842 .masterDuration = Get total duration
843 while .masterDuration < 2*.duration
844 .tmpA = .masterSourceSound
847 .masterSourceSound = Concatenate
848 selectObject: .tmpA, .tmpB
850 select .masterSourceSound
851 .masterDuration = Get total duration
853 # Get a random start point
854 .startPoint = randomUniform (0, .duration)
855 select .masterSourceSound
856 .targetSound = Extract part: .startPoint, .startPoint+.duration, "rectangular", 1, "no"
858 select .masterSourceSound
863 .scaledBubbleSource = Multiply: "yes"
864 Scale intensity: .targetIntensity - .snr
866 selectObject: .targetSound, .sourceIntTier
869 select .scaledBubbleSource
871 .filteredBubbleSource = Filter: "no"
872 Rename: "TargetBubbleSound"
873 .targetSound = Resample: .samplingFrequency, 50
875 selectObject: .scaledBubbleSource, .lpc, .filteredBubbleSource
879 Scale intensity: .targetIntensity - .snr
881 .targetSound = Create Sound: "Bubbles", 0, .duration, .samplingFrequency, "0"
889 # Select a random puls in the bubbles and add it to a random puls in the target
891 # Creates a sound with only the bubbles
893 procedure add_bubbles .sound .rate .snr .vuvTextGrid .bubblesAudioName$
896 .targetIntensity = Get intensity (dB)
897 .targetDuration = Get total duration
898 .tagetSamplingFrequency = Get sampling frequency
899 .targetNumBubbles = .rate * .targetDuration
900 .downsampled = Resample: 10000, 50
901 .lpc = To LPC (autocorrelation): 10, 0.025, 0.005, 50
903 .source = Filter (inverse)
904 .sourceInt = To Intensity: 70, 0, "yes"
905 .sourceIntTier = To IntensityTier (peaks)
912 .additiveBubblesSound = Create Sound: "Bubbles", 0, .targetDuration, .tagetSamplingFrequency, "0"
916 # Create an empty sound to receive the bubbles
917 .bubblesAudio = Read from file: .bubblesAudioName$
918 .bubblesTextGridName$ = replace_regex$(.bubblesAudioName$, "\.[a-z0-9]{2,}$", ".TextGrid", 0)
919 .bubblesTextGrid = Read from file: .bubblesTextGridName$
921 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
922 .bubblesSamplingFrequency = Get sampling frequency
923 .bubblesIntensity = Get intensity (dB)
924 .bubbleSound = Create Sound: "Bubbles", 0, .targetDuration, .bubblesSamplingFrequency, "0"
926 # Fill the new Bubbles
927 select .bubblesTextGrid
928 .numIntervals = Get number of intervals: 1
930 while .bubblesFound < .targetNumBubbles
931 .i = randomInteger(1, .numIntervals)
932 select .bubblesTextGrid
933 .label$ = Get label of interval: 1, .i
934 if .label$ = "sounding"
936 .startPoint = Get starting point: 1, .i
937 .endPoint = Get end point: 1, .i
938 .midPoint = (.startPoint + .endPoint)/2
939 .bubbleDuration = .endPoint - .startPoint
941 # Get random insertion point
942 .t = randomUniform (0.001, .targetDuration-0.001)
943 .targetStart = .t - .bubbleDuration/2
944 .targetEnd = .t + .bubbleDuration/2
946 Formula (part): .targetStart, .targetEnd, 1, 1, "self + '.sourceName$'((x - .t) + .midPoint)"
950 # Convert selected bubbles to scaled source
952 .resampledBubbleSound = Resample: .tagetSamplingFrequency, 50
954 .scaledBubbleSource = Multiply: "yes"
955 call set_VUV_to_zero .scaledBubbleSource .vuvTextGrid U
957 # The measured Intensity of the few selected bubbles can be too low. Correct for scaling
958 select .scaledBubbleSource
959 .bubbleSoundIntensity = Get intensity (dB)
960 .attenuation = .bubblesIntensity - .bubbleSoundIntensity
961 if .attenuation = undefined
965 # Scale bubble sounds
966 select .scaledBubbleSource
967 Scale intensity: .targetIntensity - .snr - .attenuation
969 select .scaledBubbleSource
971 .filteredBubbles = Filter: "no"
972 Rename: "FilteredBubbleNoise"
973 .additiveBubblesSound = Resample: .tagetSamplingFrequency, 50
976 select .resampledBubbleSound
977 plus .scaledBubbleSource
978 plus .filteredBubbles
982 plus .bubblesTextGrid
988 select .additiveBubblesSound
991 procedure add_single_bubble .sourceAudio .sourcePulses .sourceI .targetAudio .targetPulses .targetI
994 .sourceName$ = replace_regex$(selected$(), " ", "_", 0)
996 .targetName$ = replace_regex$(selected$(), " ", "_", 0)
1000 .tTarget = Get time from index: .targetI
1001 .pLeft = Get interval: .tTarget - 0.001
1002 .pRight = Get interval: .tTarget + 0.001
1005 select .sourcePulses
1006 .tSource = Get time from index: .sourceI
1007 .qLeft = Get interval: .tSource - 0.001
1008 .qRight = Get interval: .tSource + 0.001
1010 # Gaussian window parameters (FWHM Left and Right)
1011 # FWHM = 2*sqrt(2*ln(2)) * c
1012 .c = (.qLeft+.qRight)/(2*sqrt(2*ln(2)))
1013 if not( .cL = undefined or .cR = undefined)
1016 Formula (part): .tTarget-.margin, .tTarget+.margin, 1, 1, "self + '.sourceName$'((x - .tTarget) + .tSource)*exp(-1*(((x - .tTarget)/.c)^2)/2)"