summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2016-03-16 21:27:00 -0700
committeryo mama <pepper@scannerjammer.com>2016-03-16 21:27:00 -0700
commitc6d5e8f0e368c96bfeecb7501344d82820601588 (patch)
treea1339289aa5bb6ddeb0e6cf02bc8925097df199c /example.py
parent8adfb3bd99b4dcff2459756af090a640fd7a4b4a (diff)
Diffstat (limited to 'example.py')
-rwxr-xr-xexample.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/example.py b/example.py
new file mode 100755
index 0000000..38486c0
--- /dev/null
+++ b/example.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python2.7
+import wave
+import soundtouch
+from array import array
+# Open a .WAV file
+FILEPATH = "./The_beach_boys__Kokomo9_5_AD9wXuYm4a_2.wav"
+wf = wave.open(FILEPATH)
+
+# Create the sountouch pointer
+st = soundtouch.SoundTouch(wf.getframerate(), wf.getnchannels())
+
+
+# Specify the shift, as 1 whole step
+st.set_pitch_shift(2)
+
+
+
+# Feed in samples and add processed samples to resstr
+resstr = ""
+while True:
+ buf = wf.readframes(4000)
+ if not buf:
+ break
+
+ st.put_samples(buf)
+ while st.ready_count() > 0:
+ resstr += st.get_samples(4000)
+
+# Flush any additional samples
+waiting = st.waiting_count()
+ready = st.ready_count()
+flushed = ""
+
+# Add silence until another chunk is pushed out
+silence = array('h', [0] * 64)
+while st.ready_count() == ready:
+ st.put_samples(silence)
+
+# Get all of the additional samples
+while st.ready_count() > 0:
+ flushed += st.get_samples(4000)
+
+st.clear()
+
+if len(flushed) > 2 * wf.getnchannels() * waiting:
+ flushed = flushed[0:(2 * wf.getnchannels() * waiting)]
+
+resstr += flushed
+
+# Clean up
+wf.close()
+del st