Examples of splicing sound with media.py
Download Complete Example
import media
def increase_and_decrease(source):
sound = media.duplicateSound(source)
for index in range(media.getLength(sound) // 2):
value = media.getSampleValueAt(sound, index)
media.setSampleValueAt(sound, index, value * 2)
for index in range(media.getLength(sound) // 2, media.getLength(sound)):
value = media.getSampleValueAt(sound, index)
media.setSampleValueAt(sound,index, value * 0.2)
return sound
def increase_and_decrease_index(source):
sound = media.duplicateSound(source)
samples = media.getSamples(sound)
for index in range(len(samples) // 2):
value = media.getSampleValue(samples[index])
media.setSampleValue(samples[index], value * 2)
for index in range(len(samples) // 2, len(samples)):
value = media.getSampleValue(samples[index])
media.setSampleValue(samples[index], value * 0.2)
return sound
def splice_preamble(source):
target = media.makeEmptySoundBySeconds(10)
for source_index in range(0, 17408):
value = media.getSampleValueAt(source, source_index)
media.setSampleValueAt(target, source_index, value)
target_index = 17408
for source_index in range(33414, 40052):
value = media.getSampleValueAt(source, source_index)
media.setSampleValueAt(target, target_index, value)
target_index = target_index + 1
for source_index in range(17408, 26726):
value = media.getSampleValueAt(source, source_index)
media.setSampleValueAt(target, target_index, value)
target_index = target_index + 1
for index in range(0,1000):
media.setSampleValueAt(target, target_index, 0)
target_index = target_index + 1
return target
def splice_simple(source):
target = media.duplicateSound(source)
target_index=17408
for source_index in range(33414, 40052):
value = media.getSampleValueAt(source, source_index)
media.setSampleValueAt(target, target_index, value)
target_index = target_index + 1
for source_index in range(17408, 55510):
value = media.getSampleValueAt(source, source_index)
media.setSampleValueAt(target, target_index, value)
target_index = target_index + 1
return target
preamble = media.makeSound("preamble10.wav")
media.explore(preamble)
media.explore(increase_and_decrease(preamble))
media.explore(increase_and_decrease_index(preamble))
media.explore(splice_preamble(preamble))
media.explore(splice_simple(preamble))
media.quit()