Last active
September 20, 2018 00:25
-
-
Save hecanjog/b806cbb0190af0da516e0af2c8e6f5a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import numpy | |
| from pippi import dsp, fx | |
| SAMPLERATE = 44100 | |
| CHANNELS = 2 | |
| # Reading bytes from an image into a soundbuffer | |
| with open('test.jpg', 'rb') as f: | |
| b = io.BytesIO(f.read()) | |
| v = b.getbuffer() | |
| a = numpy.array(v).astype('d') | |
| snd = dsp.buffer(a, channels=CHANNELS, samplerate=SAMPLERATE) | |
| snd = fx.norm(snd, 0.5) | |
| # Could write the sound back to a file at this point | |
| snd.write('test.wav') | |
| # Or -- pippi soundbuffers have a `frames` property which | |
| # is a memoryview to the internal numpy array. | |
| # To copy bytes from a pippi soundbuffer: | |
| b = io.BytesIO(numpy.array(snd.frames).tobytes()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment