Created
April 27, 2014 07:30
-
-
Save sriramster/11339677 to your computer and use it in GitHub Desktop.
Python Audio Sampling
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 math | |
| import pyaudio | |
| import sys | |
| import numpy as np | |
| PyAudio = pyaudio.PyAudio | |
| RATE = 8000 | |
| WAVE = 1000 | |
| data = ''' | |
| ##### | |
| # | |
| # | |
| ##### | |
| # | |
| # | |
| ###### | |
| ''' | |
| data = data.split('\n') | |
| n_rows = len(data) | |
| n_cols = max(map(len, data)) | |
| for x in range(n_rows): | |
| stream = ([chr(int(math.sin(x/((RATE/WAVE)/math.pi))*127+128)) for x in xrange(RATE)]) | |
| #sin = chr(float(np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180. ))) | |
| chrstr = data[0] + (data[1]) + (data[2]) + (data[3]) | |
| data = chrstr.join(stream) | |
| #charstr = data.split('\n') | |
| p = PyAudio() | |
| stream = p.open(format = | |
| p.get_format_from_width(1), | |
| channels = 1, | |
| rate = RATE, | |
| output = True) | |
| for DISCARD in xrange(10): | |
| stream.write(data) | |
| stream.stop_stream() | |
| stream.close() | |
| p.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment