Pyaudio用声卡录制wav文件给出一个空录音

时间:2016-12-08 14:32:29

标签: python signal-processing microphone pyaudio soundcard

我一直在努力研究一个项目来检测两个流式音频信号之间的时移。我使用python3,Pyaudio,我使用带有Neumann KU-100麦克风的Motux828声卡,它采用立体声输入。所以,当我检查我的/* ------------- * * Design : FAX1 * * ------------- */ cell (FAX1) { area : 480; cell_leakage_power : 0.162133; pin(A) { direction : input; capacitance : 0.101702; rise_capacitance : 0.100648; fall_capacitance : 0.101702; } pin(B) { direction : input; capacitance : 0.0912748; rise_capacitance : 0.0912748; fall_capacitance : 0.0860056; } pin(C) { direction : input; capacitance : 0.064336; rise_capacitance : 0.064336; fall_capacitance : 0.064233; } pin(YC) { direction : output; capacitance : 0; rise_capacitance : 0; fall_capacitance : 0; max_capacitance : 0.405612; function : "(((A B)+(B C))+(C A))"; timing() { related_pin : "A"; timing_sense : positive_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.192937, 0.202293, 0.222417, 0.23603, 0.262001", \ "0.252032, 0.261902, 0.282854, 0.297212, 0.327113", \ "0.336688, 0.345538, 0.368228, 0.382804, 0.417572", \ "0.575869, 0.585084, 0.608065, 0.623073, 0.660902", \ "0.965229, 0.974557, 0.997456, 1.01213, 1.05025"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0816, 0.0804, 0.0879, 0.0939, 0.1068", \ "0.1503, 0.1476, 0.1527, 0.1587, 0.1722", \ "0.2637, 0.2625, 0.2661, 0.2682, 0.2817", \ "0.606, 0.606, 0.6069, 0.6087, 0.6159", \ "1.185, 1.185, 1.185, 1.1856, 1.1886"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.212316, 0.230368, 0.271993, 0.301851, 0.392584", \ "0.274262, 0.291144, 0.334346, 0.364751, 0.461587", \ "0.355791, 0.3728, 0.417563, 0.448945, 0.550937", \ "0.569312, 0.586364, 0.631171, 0.663795, 0.770166", \ "0.910578, 0.927654, 0.972381, 1.00471, 1.11225"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0756, 0.0777, 0.0837, 0.0891, 0.105", \ "0.1362, 0.1368, 0.1386, 0.1446, 0.162", \ "0.2247, 0.2247, 0.2292, 0.2319, 0.2487", \ "0.4911, 0.4911, 0.4917, 0.4947, 0.5031", \ "0.9528, 0.9528, 0.9528, 0.9534, 0.957"); } } timing() { related_pin : "B"; timing_sense : positive_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.201655, 0.213928, 0.238544, 0.251321, 0.282216", \ "0.259034, 0.272741, 0.300326, 0.314485, 0.347352", \ "0.344335, 0.358175, 0.387437, 0.402523, 0.438405", \ "0.584089, 0.597845, 0.62806, 0.645074, 0.683716", \ "0.97336, 0.98699, 1.01703, 1.03436, 1.07543"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0831, 0.0819, 0.0876, 0.0897, 0.0969", \ "0.15, 0.1515, 0.1563, 0.1596, 0.1704", \ "0.2637, 0.264, 0.2691, 0.2715, 0.2832", \ "0.6066, 0.6066, 0.6081, 0.6102, 0.6186", \ "1.185, 1.185, 1.185, 1.1859, 1.1907"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.221213, 0.240731, 0.285449, 0.315389, 0.41356", \ "0.283246, 0.303871, 0.352007, 0.382508, 0.482071", \ "0.366584, 0.387835, 0.439518, 0.471404, 0.573799", \ "0.583619, 0.604617, 0.657663, 0.693503, 0.801186", \ "0.925474, 0.94676, 0.999626, 1.03604, 1.14957"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0786, 0.0768, 0.0831, 0.0906, 0.1008", \ "0.1389, 0.1404, 0.1467, 0.1485, 0.1608", \ "0.2298, 0.2289, 0.2367, 0.2424, 0.2532", \ "0.495, 0.4953, 0.4974, 0.5025, 0.5145", \ "0.9543, 0.9549, 0.9546, 0.9561, 0.966"); } } timing() { related_pin : "C"; timing_sense : positive_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.185775, 0.210399, 0.245686, 0.266778, 0.312469", \ "0.243892, 0.27024, 0.307336, 0.328971, 0.375209", \ "0.329181, 0.355023, 0.394669, 0.415937, 0.465802", \ "0.568872, 0.594357, 0.633929, 0.655734, 0.706132", \ "0.957725, 0.98325, 1.0226, 1.04421, 1.09553"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0852, 0.0807, 0.0921, 0.0945, 0.1008", \ "0.1524, 0.1509, 0.1548, 0.1602, 0.1707", \ "0.2637, 0.2634, 0.2685, 0.2706, 0.2817", \ "0.606, 0.606, 0.606, 0.6081, 0.6135", \ "1.1841, 1.1844, 1.1841, 1.1847, 1.188"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.203317, 0.232392, 0.29518, 0.334702, 0.453856", \ "0.264792, 0.295214, 0.360803, 0.400337, 0.521061", \ "0.348261, 0.378841, 0.445571, 0.486885, 0.609869", \ "0.565673, 0.595953, 0.662919, 0.706274, 0.83131", \ "0.90777, 0.938204, 1.00512, 1.04815, 1.17621"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0792, 0.0765, 0.0843, 0.0912, 0.1044", \ "0.1365, 0.1401, 0.1476, 0.1494, 0.162", \ "0.2298, 0.2289, 0.2343, 0.2388, 0.2496", \ "0.4947, 0.495, 0.4965, 0.4998, 0.5079", \ "0.9543, 0.9546, 0.9546, 0.9552, 0.9612"); } } internal_power() { related_pin : "A"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "-0.007976, -0.001582, 0.046036, 0.096632, 0.303378", \ "0.003901, 0.006036, 0.053579, 0.102898, 0.293237", \ "0.004187, 0.006911, 0.054089, 0.101705, 0.286621", \ "0.002743, 0.005395, 0.051254, 0.098395, 0.279569", \ "0.001821, 0.004696, 0.050175, 0.096875, 0.276158"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.751435, 0.756822, 0.815911, 0.870229, 1.07082", \ "0.753113, 0.756525, 0.814098, 0.868209, 1.05967", \ "0.752309, 0.755483, 0.812912, 0.865268, 1.05629", \ "0.751447, 0.754547, 0.811504, 0.863135, 1.04992", \ "0.751138, 0.754253, 0.811014, 0.862398, 1.04726"); } } internal_power() { related_pin : "B"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.079095, 0.071988, 0.108511, 0.145461, 0.323354", \ "0.087668, 0.081948, 0.11915, 0.154305, 0.313515", \ "0.088238, 0.082519, 0.119066, 0.154328, 0.306697", \ "0.086954, 0.081108, 0.116745, 0.152259, 0.302454", \ "0.086343, 0.080371, 0.115854, 0.151083, 0.299904"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.697594, 0.691911, 0.738172, 0.776694, 0.94822", \ "0.698733, 0.693453, 0.736748, 0.780343, 0.935934", \ "0.69733, 0.692467, 0.734847, 0.777073, 0.936829", \ "0.694698, 0.690931, 0.732109, 0.774157, 0.931782", \ "0.694056, 0.690307, 0.731288, 0.773142, 0.929401"); } } internal_power() { related_pin : "C"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.163673, 0.165668, 0.189463, 0.22829, 0.390871", \ "0.165439, 0.17055, 0.197339, 0.235655, 0.382059", \ "0.166138, 0.169989, 0.199144, 0.23583, 0.377468", \ "0.166578, 0.169587, 0.197806, 0.233484, 0.371962", \ "0.166896, 0.169673, 0.197451, 0.232882, 0.369249"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.583181, 0.587626, 0.631498, 0.669882, 0.82487", \ "0.585184, 0.588504, 0.631341, 0.669054, 0.811996", \ "0.585161, 0.586867, 0.628181, 0.667229, 0.810344", \ "0.582139, 0.584993, 0.625643, 0.66373, 0.805293", \ "0.581744, 0.584612, 0.625012, 0.662479, 0.802606"); } } } pin(YS) { direction : output; capacitance : 0; rise_capacitance : 0; fall_capacitance : 0; max_capacitance : 0.409456; function : "((A^B)^C)"; timing() { related_pin : "A"; timing_sense : non_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.311797, 0.328706, 0.370858, 0.401209, 0.489974", \ "0.367147, 0.383417, 0.426146, 0.453648, 0.544812", \ "0.446564, 0.463136, 0.505936, 0.532612, 0.62307", \ "0.679909, 0.69597, 0.739454, 0.766625, 0.856786", \ "1.06837, 1.08444, 1.12769, 1.15482, 1.24479"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0762, 0.0753, 0.0768, 0.0777, 0.078", \ "0.1437, 0.1443, 0.1437, 0.1428, 0.1455", \ "0.2535, 0.2544, 0.2544, 0.2538, 0.2538", \ "0.5994, 0.5994, 0.5997, 0.5997, 0.6", \ "1.1832, 1.1832, 1.1829, 1.1835, 1.1832"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.299535, 0.309958, 0.329301, 0.341262, 0.363669", \ "0.357539, 0.367622, 0.38617, 0.399449, 0.421082", \ "0.434309, 0.445615, 0.464819, 0.476385, 0.49848", \ "0.644759, 0.656249, 0.67551, 0.68687, 0.70887", \ "0.985959, 0.997573, 1.01673, 1.02809, 1.04987"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0753, 0.0756, 0.0726, 0.0774, 0.0798", \ "0.1323, 0.1299, 0.1314, 0.1329, 0.1341", \ "0.2184, 0.2187, 0.2187, 0.2184, 0.2187", \ "0.4881, 0.4881, 0.4884, 0.4887, 0.4884", \ "0.9525, 0.9525, 0.9528, 0.9531, 0.9525"); } } timing() { related_pin : "B"; timing_sense : non_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.326354, 0.343646, 0.392103, 0.426361, 0.525078", \ "0.381898, 0.400236, 0.44672, 0.478563, 0.576663", \ "0.462937, 0.480605, 0.527821, 0.559818, 0.65523", \ "0.698543, 0.715548, 0.762286, 0.793601, 0.888746", \ "1.08749, 1.10456, 1.15106, 1.18221, 1.27704"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0774, 0.0786, 0.0801, 0.0822, 0.0807", \ "0.1482, 0.1467, 0.1479, 0.1461, 0.1464", \ "0.2568, 0.2568, 0.2571, 0.2553, 0.2547", \ "0.6012, 0.6012, 0.6012, 0.6006, 0.6003", \ "1.1838, 1.1841, 1.1841, 1.1838, 1.1838"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.311475, 0.321628, 0.34643, 0.359418, 0.388969", \ "0.368563, 0.378796, 0.403685, 0.415647, 0.443952", \ "0.446227, 0.456405, 0.482051, 0.493458, 0.521028", \ "0.656751, 0.667049, 0.692618, 0.704328, 0.731082", \ "0.998102, 1.00844, 1.03396, 1.04592, 1.07192"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0771, 0.0768, 0.075, 0.0765, 0.0768", \ "0.1341, 0.1341, 0.1326, 0.1314, 0.1314", \ "0.219, 0.2187, 0.2178, 0.2187, 0.2172", \ "0.4881, 0.4884, 0.4881, 0.4881, 0.4875", \ "0.9531, 0.9531, 0.9528, 0.9528, 0.9522"); } } timing() { related_pin : "C"; timing_sense : non_unate; cell_rise(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.322002, 0.346854, 0.408441, 0.447656, 0.560705", \ "0.376032, 0.403646, 0.463433, 0.50045, 0.613575", \ "0.455609, 0.483999, 0.542842, 0.580766, 0.69238", \ "0.690799, 0.71776, 0.777098, 0.815784, 0.926969", \ "1.07981, 1.10678, 1.16586, 1.20454, 1.31715"); } rise_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.0783, 0.0798, 0.0804, 0.0753, 0.0765", \ "0.1482, 0.1461, 0.1461, 0.1443, 0.1443", \ "0.2562, 0.2568, 0.2565, 0.2565, 0.255", \ "0.6012, 0.6012, 0.6018, 0.6021, 0.603", \ "1.1844, 1.1844, 1.1841, 1.1844, 1.1862"); } cell_fall(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.296791, 0.3165, 0.344383, 0.367168, 0.404984", \ "0.350874, 0.372846, 0.399754, 0.421069, 0.455738", \ "0.424904, 0.447341, 0.475681, 0.494426, 0.531328", \ "0.632276, 0.654496, 0.683205, 0.702501, 0.738492", \ "0.973424, 0.995389, 1.02414, 1.04363, 1.07937"); } fall_transition(delay_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.072, 0.0708, 0.0678, 0.0759, 0.0699", \ "0.1242, 0.1236, 0.1236, 0.1236, 0.1218", \ "0.2118, 0.2118, 0.2118, 0.21, 0.2106", \ "0.4839, 0.4839, 0.4842, 0.4848, 0.4839", \ "0.9513, 0.9516, 0.9519, 0.9519, 0.9519"); } } internal_power() { related_pin : "A"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.751435, 0.756822, 0.815911, 0.870229, 1.07082", \ "0.753113, 0.756525, 0.814098, 0.868209, 1.05967", \ "0.752309, 0.755483, 0.812912, 0.865268, 1.05629", \ "0.751447, 0.754547, 0.811504, 0.863135, 1.04992", \ "0.751138, 0.754253, 0.811014, 0.862398, 1.04726"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "-0.007976, -0.001582, 0.046036, 0.096632, 0.303378", \ "0.003901, 0.006036, 0.053579, 0.102898, 0.293237", \ "0.004187, 0.006911, 0.054089, 0.101705, 0.286621", \ "0.002743, 0.005395, 0.051254, 0.098395, 0.279569", \ "0.001821, 0.004696, 0.050175, 0.096875, 0.276158"); } } internal_power() { related_pin : "B"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.697594, 0.691911, 0.738172, 0.776694, 0.94822", \ "0.698733, 0.693453, 0.736748, 0.780343, 0.935934", \ "0.69733, 0.692467, 0.734847, 0.777073, 0.936829", \ "0.694698, 0.690931, 0.732109, 0.774157, 0.931782", \ "0.694056, 0.690307, 0.731288, 0.773142, 0.929401"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.079095, 0.071988, 0.108511, 0.145461, 0.323354", \ "0.087668, 0.081948, 0.11915, 0.154305, 0.313515", \ "0.088238, 0.082519, 0.119066, 0.154328, 0.306697", \ "0.086954, 0.081108, 0.116745, 0.152259, 0.302454", \ "0.086343, 0.080371, 0.115854, 0.151083, 0.299904"); } } internal_power() { related_pin : "C"; rise_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.583181, 0.587626, 0.631498, 0.669882, 0.82487", \ "0.585184, 0.588504, 0.631341, 0.669054, 0.811996", \ "0.585161, 0.586867, 0.628181, 0.667229, 0.810344", \ "0.582139, 0.584993, 0.625643, 0.66373, 0.805293", \ "0.581744, 0.584612, 0.625012, 0.662479, 0.802606"); } fall_power(energy_template_5x5) { index_1 ("0.015, 0.04, 0.08, 0.2, 0.4"); index_2 ("0.06, 0.18, 0.42, 0.6, 1.2"); values ( \ "0.163673, 0.165668, 0.189463, 0.22829, 0.390871", \ "0.165439, 0.17055, 0.197339, 0.235655, 0.382059", \ "0.166138, 0.169989, 0.199144, 0.23583, 0.377468", \ "0.166578, 0.169587, 0.197806, 0.233484, 0.371962", \ "0.166896, 0.169673, 0.197451, 0.232882, 0.369249"); } } } } 时,我是正确的,这是与MOTU声卡连接的第4个。

然而,当我录制时:

input_device_index

我录制的没有声音的波形文件,几乎没有噪音(自然)

此外,我可以使用特定麦克风录制第三方软件。 它完全正常。

注意: 声卡通常为24位深度,我还尝试import time import pyaudio import wave CHUNK = 1024 * 3 # Chunk is the bytes which are currently processed FORMAT = pyaudio.paInt16 RATE = 44100 RECORD_SECONDS = 2 WAVE_OUTPUT = "temp.wav" p = pyaudio.PyAudio() stream = p.open(format=FORMAT,channels=2,rate=RATE,input=True,frames_per_buffer=CHUNK,input_device_index=4) frames = [] # np array storing all the data for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream1.read(CHUNK) frames.append(data1) stream.stop_stream() stream.close() p.terminate() wavef = wave.open(WAVE_OUTPUT, 'wb') # opening the file wavef.setnchannels(1) wavef.setsampwidth(p.get_sample_size(FORMAT)) wavef.setframerate(RATE) wavef.writeframes(b''.join(frames1)) # writing the data to be saved wavef.close() 录制带有纯噪音的波形文件

1 个答案:

答案 0 :(得分:0)

我认为你提到了错误的变量名称,因为我看到了你的代码。错误的变量是:

data = stream1.read(CHUNK) 
frames.append(data1)
wavef.writeframes(b''.join(frames1))

正确的值是:

data = stream.read(CHUNK)
frames.append(data)
wavef.writeframes(b''.join(frames))