Skip to content

Commit

Permalink
Add an example of phase vocoder based time stretch and pitch shift ca…
Browse files Browse the repository at this point in the history
…pabilities
  • Loading branch information
JohnVinyard committed May 30, 2018
1 parent 7a9d0c9 commit 26353ac
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/effects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import zounds
from zounds.spectral import time_stretch, pitch_shift
from zounds.ui import AppSettings
import argparse

sr = zounds.SR11025()
BaseModel = zounds.stft(resample_to=sr, store_resampled=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
pass


if __name__ == '__main__':
parser = argparse.ArgumentParser(parents=[
AppSettings()
])
parser.add_argument(
'--sound-uri',
default='https://archive.org/download/LucaBrasi2/06-Kevin_Gates-Out_The_Mud_Prod_By_The_Runners_The_Monarch.ogg')
args = parser.parse_args()

_id = Sound.process(meta=args.sound_uri)
snd = Sound(_id)

original = snd.resampled
slow = zounds.AudioSamples(time_stretch(original, 0.75).squeeze(), sr)
fast = zounds.AudioSamples(time_stretch(original, 1.25).squeeze(), sr)

higher = zounds.AudioSamples(
pitch_shift(original[:zounds.Seconds(10)], 1.0).squeeze(), sr)
lower = zounds.AudioSamples(
pitch_shift(original[:zounds.Seconds(10)], -1.0).squeeze(), sr)

app = zounds.ZoundsApp(
model=Sound,
visualization_feature=Sound.fft,
audio_feature=Sound.resampled,
globals=globals(),
locals=locals(),
secret=args.app_secret)

app.start(args.port)

0 comments on commit 26353ac

Please sign in to comment.