Created
June 1, 2017 14:36
-
-
Save denisb411/7c6f601175e8bb9f735d8aa43a0db340 to your computer and use it in GitHub Desktop.
Python code that collects the audio input samples
This file contains 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 pyaudio | |
import numpy as np | |
import time | |
import wave | |
import matplotlib.pyplot as plt | |
# open stream | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 44100 | |
CHUNK = 512 # RATE / number of updates per second | |
p=pyaudio.PyAudio() | |
stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,frames_per_buffer=CHUNK) | |
t1=time.time() | |
data = stream.read(CHUNK, exception_on_overflow=False) | |
waveData = wave.struct.unpack("%dh"%(CHUNK), data) | |
samplePython = np.array(waveData, dtype = np.float) | |
print (samplePython) | |
print len(samplePython) | |
sampleIOS = np.array([0.0166742969, 0.0181432627, 0.0184620395, 0.0182254426, 0.0181945376, 0.0185530782, 0.0192517322, 0.0199078992, 0.0204724055, 0.0212812237, 0.022370765, 0.0230008475, 0.0225516111, 0.0213304944, 0.0200473778, 0.019841563, 0.0206818394, 0.0211550407, 0.0207783803, 0.020227218, 0.0199668743, 0.0204207543, 0.0212149825, 0.0206389967, 0.0187880248, 0.0167767145, 0.0150565384, 0.01393665, 0.0129076103, 0.0122165764, 0.0126033062, 0.0133863436, 0.0136517091, 0.0134775555, 0.0128802266, 0.0110962093, 0.00905595906, 0.00834821165, 0.00822720397, 0.008329398, 0.00930604525, 0.0108533269, 0.0116535304, 0.0108615728, 0.00948433205, 0.00845594145, 0.0073993206, 0.00526688294, 0.00247669267, 0.00111255911, 0.00186654506, 0.00393201364, 0.00605870783, 0.00728464406, 0.00758164795, 0.00741813984, 0.0070983395, 0.00691324845, 0.00665103039, 0.00544488989, 0.00439271377, 0.00472383248, 0.00460877642, 0.0031108777, 0.00130207348, 2.82817055e-05, -0.000548420125, -0.000275739003, 0.000828514865, 0.00180396682, 0.00270708348, 0.00306540378, 0.00239821919, 0.00103933609, -0.000685598003, -0.00136318523, -0.000453095679, 0.00125991693, 0.00238831784, 0.00296153524, 0.00338690123, 0.0032403036, 0.00288192695, 0.00179502275, 0.000141638375, -0.000294534751, 0.000546510215, 0.000953074254, 0.00124290399, 0.00231291493, 0.002664509, 0.00187232892, 0.000950978196, -0.000329779927, -0.00240250281, -0.00479977485, -0.00740027241, -0.00969557092, -0.0106855575, -0.0104641449, -0.00997615233, -0.00959131029, -0.00918646995, -0.00915261451, -0.00987057015, -0.0118814595, -0.0142864706, -0.01508094, -0.0143546984, -0.013356979, -0.0120444689, -0.0105897496, -0.00989883766, -0.00958041474, -0.00935341883, -0.009513909, -0.00960636325, -0.00840403326, -0.00590613624, -0.00342813251, -0.00265052519, -0.00432227273, -0.00567610376, -0.00536336983, -0.00523859542, -0.00563341565, -0.00470317388, -0.0030363095, -0.00235861051, -0.00161369948, -0.000933674513, -0.000760104507, -0.000997926109, -0.000567235518, 0.000787643949, 0.00195078983, 0.00361918472, 0.00577382138, 0.00791249052, 0.00881891698, 0.00900129974, 0.0103553394, 0.0116630699, 0.012568742, 0.0140690384, 0.0155559797, 0.0160660781, 0.0156202205, 0.0145593546, 0.013330535, 0.0133768162, 0.0145495879, 0.0153538212, 0.0157531928, 0.0163016655, 0.0165446326, 0.0157131739, 0.014445262, 0.0137766153, 0.0140172113, 0.0144918887, 0.0149374977, 0.0149037559, 0.0132588232, 0.0116981799, 0.0113050332, 0.0108932955, 0.0107115926, 0.0105215162, 0.00955812354, 0.00791457389, 0.00634178892, 0.00577708986, 0.00634926744, 0.00757213589, 0.00908713695, 0.0102157779, 0.0102131637, 0.00932934694, 0.00779415527, 0.00633388292, 0.00510790199, 0.00394995604, 0.00369091891, 0.0041834712, 0.0045331656, 0.00425316021, 0.00285571301, 0.000195333385, -0.00225465652, -0.003475826, -0.00370169012, -0.00307752332, -0.00267249416, -0.00307517592, -0.00317477342, -0.00324952253, -0.00388857024, -0.00477789296, -0.00594020449, -0.00680366484, -0.00695240404, -0.00644947169, -0.00682629552, -0.00833404623, -0.00919884909, -0.00970366225, -0.0109844515, -0.0124453558, -0.0127294958, -0.0122284787, -0.011933405, -0.0121762576, -0.0126155792, -0.0130743301, -0.0138008753, -0.014536716, -0.0150960898, -0.0152501361, -0.0149841355, -0.0149593707, -0.0157790072, -0.017874632, -0.0204565395, -0.022203071, -0.0233681612, -0.0238094889, -0.0232296474, -0.0221874882, -0.0209106337, -0.0195935555, -0.0185538139, -0.0182225127, -0.0182592887, -0.017962059, -0.01806207, -0.0189136658, -0.0198350772, -0.0201944243, -0.0198207237, -0.0196199324, -0.0192558654, -0.0182592422, -0.0172010642, -0.016385816, -0.0166466702, -0.0176436808, -0.0178364776, -0.0174655411, -0.0174071919, -0.0171253178, -0.0163532905, -0.0159844514, -0.0163361039, -0.0156097524, -0.0138400905, -0.0129847592, -0.0133175282, -0.0143788615, -0.0154124368, -0.0165268127, -0.016205417, -0.0131596522, -0.0100341327, -0.00810160302, -0.00714962138, -0.00725041004, -0.00795981102, -0.00918190554, -0.00996225886, -0.00912048481, -0.00691479864, -0.00468519051, -0.00314685632, -0.0021960747, -0.00199719053, -0.00252982345, -0.00348964357, -0.00419279467, -0.00422798935, -0.00359291653, -0.0022652403, -0.000428059167, 0.00104600599, 0.00140719593, 0.0011200211, 0.000685207138, 0.000113791364, 3.88855988e-05, 0.000560014509, 0.000833788479, 0.00150346756, 0.00270742807, 0.00317105628, 0.00298314984, 0.00326228119, 0.00389773678, 0.00360399229, 0.00253666146, 0.00196696841, 0.00189540593, 0.00149470649, 0.000646675471, -0.000309229421, -0.00121670787, -0.00180792157, -0.00178890105, -0.00134006492, -0.000947950059, -0.000375345175, 0.000548117154, 0.000612663978, -0.000179517563, -0.00046877042, -0.000713831745, -0.00130639039, -0.00115250063, -0.000401128433, 8.43893213e-06, 9.80841724e-05, 0.000160933298, 0.000242770038, 0.00037189282, 0.000939299003, 0.0018746322, 0.00268803793, 0.00371026294, 0.00490916008, 0.00645616185, 0.00815859716, 0.00897844881, 0.00919948146, 0.00932673179, 0.00932347775, 0.00889593922, 0.00815556571, 0.00699984422, 0.00591221964, 0.00585833797, 0.00599497976, 0.00608810363, 0.00611883728, 0.00554861501, 0.00478089647, 0.0041280766, 0.00323865865, 0.00230450695, 0.00245031901, 0.00345543702, 0.00466694264, 0.00602069823, 0.00708241062, 0.00792000443, 0.00826650113, 0.00760533148, 0.00656850543, 0.00608696137, 0.00563321961, 0.00497167418, 0.00515678711, 0.00589134824, 0.00651839748, 0.00773057062, 0.00951963104, 0.0104074292, 0.0103402026, 0.00959876925, 0.00869175512, 0.00883141533, 0.00921741314, 0.00952272024, 0.00976403896, 0.00962156523, 0.00946840085, 0.00912690628, 0.00838084146, 0.00719855679, 0.00612006057, 0.00508639216, 0.00344174518, 0.00231468794, 0.002548991, 0.00313667255, 0.00339010172, 0.00353729818, 0.00368634518, 0.00404420681, 0.00452937372, 0.00453997497, 0.00444281148, 0.00441872189, 0.00395125151, 0.00369956996, 0.00430630008, 0.00503215101, 0.00532116275, 0.00530187506, 0.00548341684, 0.00627177022, 0.00689774938, 0.00712499348, 0.00769223226, 0.00834856555, 0.00857403129, 0.00856936723, 0.00892482046, 0.00938677136, 0.00939361565, 0.00890852977, 0.00744162733, 0.00597251952, 0.00604352029, 0.0072615426, 0.00851922669, 0.00932225119, 0.00986795221, 0.0102727804, 0.0111526949, 0.0120574264, 0.0119840382, 0.0115803191, 0.0106135178, 0.00887837447, 0.00743423216, 0.00636650808, 0.00564285228, 0.00608847197, 0.00714629795, 0.0073616514, 0.00680178311, 0.005975354, 0.00523915933, 0.00453455839, 0.00316534936, 0.00160318695, 0.00109480729, 0.00125845359, 0.0011264364, 0.00127730554, 0.00153403438, 0.00118426385, 0.000990947359, 0.00118378073, 0.00142845116, 0.00199155393, 0.00311323744, 0.00430496782, 0.00462754583, 0.00446326379, 0.0046243486, 0.00479162252, 0.00449020788, 0.00383518729, 0.0036004181, 0.00337297632, 0.00233287551, 0.00119307498, 0.000361317972, -0.000451587955, -0.00129602442, -0.00206315308, -0.00239193835, -0.00224468787, -0.00217490573, -0.00178618659, -0.000537406828, 0.000972087379, 0.00184453104, 0.00183571037, 0.00177428732, 0.00157028937, 0.00078804011, 0.000109048429, -0.000253635168, -0.0008668683, -0.0018214368, -0.00268969825, -0.00339316926, -0.00387349795, -0.00416592043, -0.00375057245, -0.00243047997, -0.00136951392, -0.000896824815, -0.000389610475, -0.00023306605, -0.00123832119, -0.0023618252, -0.00269813556, -0.00269723777, -0.00262019993, -0.00278035202, -0.00343789672, -0.00422962755, -0.00457859738, -0.00448848773, -0.0042332639, -0.00454310095, -0.00519116689, -0.00504383957, -0.0046887002, -0.0049972143, -0.00513264164, -0.00454299198, -0.00442452775, -0.00487452094, -0.00478166202, -0.00421700114, -0.00384462974, -0.00396334799, -0.00405589631, -0.00388578884], dtype = np.float) | |
print (sampleIOS) | |
print len(sampleIOS) | |
fig = plt.figure(figsize=(10,8)) | |
ax1 = fig.add_subplot(211) | |
ax2 = fig.add_subplot(212) | |
ax1.cla() | |
ax1.plot(samplePython) | |
ax1.grid() | |
ax2.cla() | |
ax2.plot(sampleIOS) | |
ax2.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment