AudioReplace[audio,{t1,t2}new]
replaces the audio signal between t1 and t2 with the new signal new.
AudioReplace[audio,{{t11,t12},…}new]
replaces multiple intervals with the same audio new.
AudioReplace[audio,{{t11,t12}new1,…}]
replaces multiple intervals.
AudioReplace[audio,{t1,t2}new,fitting]
uses the specified fitting method.
AudioReplace
AudioReplace[audio,{t1,t2}new]
replaces the audio signal between t1 and t2 with the new signal new.
AudioReplace[audio,{{t11,t12},…}new]
replaces multiple intervals with the same audio new.
AudioReplace[audio,{{t11,t12}new1,…}]
replaces multiple intervals.
AudioReplace[audio,{t1,t2}new,fitting]
uses the specified fitting method.
Details
- AudioReplace can be used to replace a part of an audio signal with a new signal. Typically, the duration of the whole audio stays unchanged.
- The time t can be any of the following:
-
t time given in seconds Quantity[t,"unit"] time given in "unit" compatible with seconds Quantity[t,"Samples"] time given as number of samples - The fitting method specifies how new replaces the {t1,t2} interval. Possible settings are:
-
"Fill" pad or trim new to duration t2-t1 (default) "Insert" remove audio from t1 to t2 and insert new at t1 "Stretch" replace {t1,t2} with the time-stretched version of new
Examples
open all close allBasic Examples (1)
Scope (3)
Basic Uses (2)
Replace different intervals with the same signal:
a = \!\(\*AudioBox[""]\);AudioReplace[a, {{.5, 1}, {1.3, 1.6}} -> AudioGenerator["Sin"]]Insert different signals at different times:
a = \!\(\*AudioBox[""]\);AudioReplace[a, {{.5, 1} -> AudioGenerator["Sin"], {1.3, 1.6} -> AudioGenerator["White"]}]Fitting (1)
Use the fitting to control the behavior of the replacement signal:
a = ExampleData[{"Audio", "Drums"}, "Audio"];Duration[a]b = \!\(\*AudioBox[""]\);By default, the replacement audio is trimmed or padded to the specified length:
AudioReplace[a, {.5, 1.5} -> b, "Fill"]The duration of the input signal stays the same:
Duration[%]Use "Insert" to avoid any trimming or padding of the replacement audio:
AudioReplace[a, {.5, 1.5} -> b, "Insert"]The duration changes if the duration of the replacement is different from the interval:
Duration[%]Use "Stretch" to time stretch the replacement audio to the desired duration:
AudioReplace[a, {.5, 1.5} -> b, "Stretch"]The duration of the input signal does not change:
Duration[%]Applications (3)
Replace the quiet parts of a recording with silence:
a = ExampleData[{"Audio", "NoisyTalk"}, "Audio"]int = AudioIntervals[a, #LoudnessEBU < -28&]Replace the selected intervals with silence:
AudioReplace[a, int -> AudioGenerator["Silence"]]AudioPlot[%]Replace parts of a recording with a new audio signal:
a = ExampleData[{"Audio", "PianoScale"}, "Audio"]Find the intervals with a nonzero amplitude and the fundamental frequency in a specified range:
int = AudioIntervals[a, #RMSAmplitude > .001 && TrueQ[#FundamentalFrequency > 280]&, PartitionGranularity -> .1]Display the resulting intervals:
AudioPlot[a, Epilog -> {RGBColor[1, 0, 0, .2], Rectangle[{#[[1]], -1}, {#[[2]], 1}]& /@ int}]Prepare the replacement audio:
b = AudioTrim[ExampleData[{"Audio", "Piano"}, "Audio"], 2];Replace the selected intervals with the replacement audio:
AudioReplace[a, int -> b, "Stretch"]AudioPlot[%]Correct the pitch of parts of a recording:
a = ExampleData[{"Audio", "PianoScale"}, "Audio"]Find the intervals with a nonzero amplitude and the fundamental frequency in a specified range:
int = AudioIntervals[a, #RMSAmplitude > .001 && TrueQ[#FundamentalFrequency > 280]&, PartitionGranularity -> .1]AudioLocalMeasurements[a, "FundamentalFrequency"]//ListLinePlotDefine the target frequencies:
targetFrequencies = {286, 271, 256};Define the pitch-shifting algorithm:
f[audio_, targetFreq_] := AudioPitchShift[audio, targetFreq / Mean@AudioLocalMeasurements[audio, "FundamentalFrequency", MissingDataMethod -> "Interpolation"]]replacements = Table[int[[i]] -> f[AudioTrim[a, int[[i]]], targetFrequencies[[i]]], {i, Length@int}];AudioReplace[a, replacements]AudioLocalMeasurements[%, "FundamentalFrequency"]//ListLinePlotRelated Guides
History
Text
Wolfram Research (2017), AudioReplace, Wolfram Language function, https://reference.wolfram.com/language/ref/AudioReplace.html.
CMS
Wolfram Language. 2017. "AudioReplace." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AudioReplace.html.
APA
Wolfram Language. (2017). AudioReplace. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AudioReplace.html
BibTeX
@misc{reference.wolfram_2026_audioreplace, author="Wolfram Research", title="{AudioReplace}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/AudioReplace.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_audioreplace, organization={Wolfram Research}, title={AudioReplace}, year={2017}, url={https://reference.wolfram.com/language/ref/AudioReplace.html}, note=[Accessed: 13-June-2026]}