├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── icon.png ├── pyAudioAnalysis ├── MidTermFeatures.py ├── ShortTermFeatures.py ├── __init__.py ├── audacityAnnotation2WAVs.py ├── audioAnalysis.py ├── audioBasicIO.py ├── audioSegmentation.py ├── audioTrainTest.py ├── audioVisualization.py ├── convertToWav.py ├── data │ ├── 3WORDS.wav │ ├── beat │ │ ├── 100 BPM - Rhythm patterns - Salsa.mp3 │ │ ├── 120 BPM Techno Drum Loop.mp3 │ │ ├── 170 BPM - Simple Straight Beat - Drum Track.mp3 │ │ ├── 200 BPM (goa psy trance).mp3 │ │ └── small.wav │ ├── computational.sh │ ├── count.segments │ ├── count.wav │ ├── count2.segments │ ├── count2.wav │ ├── diarizationExample.segments │ ├── diarizationExample.wav │ ├── diarizationExample2.segments │ ├── diarizationExample2.wav │ ├── diarizationResults.xls │ ├── doremi.wav │ ├── hmmRadioSM │ ├── matSegToCSV.m │ ├── matSegToCSV_dir.m │ ├── models │ │ ├── knnMusicGenre6 │ │ ├── knnSM │ │ ├── knn_4class │ │ ├── knn_movie8class │ │ ├── knn_musical_genre_6 │ │ ├── knn_sm │ │ ├── knn_speaker_10 │ │ ├── knn_speaker_male_female │ │ ├── svm_rbf_4class │ │ ├── svm_rbf_4classMEANS │ │ ├── svm_rbf_movie8class │ │ ├── svm_rbf_movie8classMEANS │ │ ├── svm_rbf_musical_genre_6 │ │ ├── svm_rbf_musical_genre_6MEANS │ │ ├── svm_rbf_sm │ │ ├── svm_rbf_smMEANS │ │ ├── svm_rbf_speaker_10 │ │ ├── svm_rbf_speaker_10MEANS │ │ ├── svm_rbf_speaker_male_female │ │ └── svm_rbf_speaker_male_femaleMEANS │ ├── recordRadio.py │ ├── recording1.wav │ ├── recording2.wav │ ├── recording3.wav │ ├── scottish.segments │ ├── scottish.wav │ ├── similarities.html │ ├── speechEmotion │ │ ├── 00.wav │ │ ├── 01.wav │ │ ├── 02.wav │ │ ├── 03.wav │ │ ├── 04.wav │ │ ├── 05.wav │ │ ├── 06.wav │ │ ├── 07.wav │ │ ├── 08.wav │ │ ├── 09.wav │ │ ├── 10.wav │ │ ├── 11.wav │ │ ├── 12.wav │ │ ├── 13.wav │ │ ├── 14.wav │ │ ├── 15.wav │ │ ├── 16.wav │ │ ├── 17.wav │ │ ├── 18.wav │ │ ├── 19.wav │ │ ├── 20.wav │ │ ├── 21.wav │ │ ├── 22.wav │ │ ├── 23.wav │ │ ├── 24.wav │ │ ├── 25.wav │ │ ├── 26.wav │ │ ├── 27.wav │ │ ├── 28.wav │ │ ├── 29.wav │ │ ├── 30.wav │ │ ├── 31.wav │ │ ├── 32.wav │ │ ├── 33.wav │ │ ├── 34.wav │ │ ├── 35.wav │ │ ├── 36.wav │ │ ├── 37.wav │ │ ├── 38.wav │ │ ├── 39.wav │ │ ├── 40.wav │ │ ├── 41.wav │ │ ├── 42.wav │ │ ├── 43.wav │ │ ├── 44.wav │ │ ├── 45.wav │ │ ├── 46.wav │ │ ├── arousal.csv │ │ └── valence.csv │ ├── speech_music_sample.wav │ ├── style.css │ ├── svm5ClassesMEANS │ ├── svmSpeakerFemaleMale │ ├── svmSpeakerFemaleMaleMEANS │ ├── testComputational.py │ └── trsToSegmentsFile.m └── utilities.py ├── pytests ├── test_data │ ├── 1_sec_wav.wav │ ├── 3_class │ │ ├── music │ │ │ ├── m_65745_0.0_1.0.wav │ │ │ ├── m_65795_0.0_1.0.wav │ │ │ ├── m_66851_0.0_1.0.wav │ │ │ ├── m_66860_0.0_1.0.wav │ │ │ ├── m_66866_0.0_1.0.wav │ │ │ ├── m_69588_0.0_1.0.wav │ │ │ ├── m_99094_0.0_1.0.wav │ │ │ ├── m_ACDC20-20Thunderstruck1_0.0_1.0.wav │ │ │ ├── m_Abigail_Lapell-Dress_Rehearsal_0.0_1.0.wav │ │ │ ├── m_Accept20-20Breaker20-200920-20Breaking20Up20Again_0.0_1.0.wav │ │ │ ├── m_Accept20-20Metal20heart_0.0_1.0.wav │ │ │ ├── m_Alex_Niedt-But_I_Love_You____0.0_1.0.wav │ │ │ ├── m_Alvin202620The20Chipmunks20-20Play20That20Funky20Music2028remake29_0.0_1.0.wav │ │ │ ├── m_Amorphis20-20Alone_0.0_1.0.wav │ │ │ ├── m_Amorphis20-20Summer27s20End_0.0_1.0.wav │ │ │ ├── m_Anders_Tengdahl-I_came_here_to_see_you_0.0_1.0.wav │ │ │ ├── m_Arch20Enemy20-20Heart20of20Darkness_0.0_1.0.wav │ │ │ ├── m_Arch20Enemy20-20Savage20Messiah_0.0_1.0.wav │ │ │ ├── m_Arch20Enemy20-20We20Will20Rise_0.0_1.0.wav │ │ │ ├── m_At20The20Gates20-20Suicide20Nation_0.0_1.0.wav │ │ │ ├── m_BB_CHUNG_KING_AND_THE_BUDDAHEADS-LITTLE_GIRL_0.0_1.0.wav │ │ │ ├── m_Barry20White20-20Can27t20Get20Enough20Of20Your20Love20Baby_0.0_1.0.wav │ │ │ ├── m_Bee20Gees20-20Jive20Talkin27_0.0_1.0.wav │ │ │ ├── m_Bee20Gees20-20Tragedy_0.0_1.0.wav │ │ │ ├── m_Bee20Gees20-20You20Should20Be20Dancing_0.0_1.0.wav │ │ │ ├── m_Blondie20-20Heart20Of20Glass_0.0_1.0.wav │ │ │ ├── m_Bloodhound20Gang20-20I20Hope20You20Die_0.0_1.0.wav │ │ │ ├── m_Bloodhound20Gang20-20The20Roof20Is20On20Fire_0.0_1.0.wav │ │ │ ├── m_Blue_Steele-We_re_Gonna_Move_0.0_1.0.wav │ │ │ ├── m_Bohannon20-20Foot20Stompin2720Music_0.0_1.0.wav │ │ │ ├── m_Bullet20For20My20Valentine20-20Spit20You20Out_0.0_1.0.wav │ │ │ ├── m_Cabrini-Winter_2000_0.0_1.0.wav │ │ │ ├── m_Canibal20Corpse20-20Execution_0.0_1.0.wav │ │ │ ├── m_Carcass20-20Death20Certificate_0.0_1.0.wav │ │ │ ├── m_Cassidy-Love_You_Like_My_Radio_0.0_1.0.wav │ │ │ ├── m_Celtic20Frost20-20Eternal20summer_0.0_1.0.wav │ │ │ ├── m_Chevelle20-20The20Red_0.0_1.0.wav │ │ │ ├── m_Dan20Hartman20-20Instant20Replay_0.0_1.0.wav │ │ │ ├── m_David_Rotundo_and_the_Blue_Canadians-Butt_Bustin__Boogie_0.0_1.0.wav │ │ │ └── m_Deathstars20-20Damn20Me_0.0_1.0.wav │ │ ├── silence │ │ │ ├── n_IJI9R1NTO9_57.0_58.0.wav │ │ │ ├── n_IMBOEI4DBL_374.0_375.0.wav │ │ │ ├── n_IOBEWT1S55_174.0_175.0.wav │ │ │ ├── n_J950HTM138_56.0_57.0.wav │ │ │ ├── n_JK5EBWE26L_307.0_308.0.wav │ │ │ ├── n_JL9T5RK51P_90.0_91.0.wav │ │ │ ├── n_JMO0MW96YK_129.0_130.0.wav │ │ │ ├── n_JOL1SORBQE_2.0_3.0.wav │ │ │ ├── n_JQZM71SOHD_113.0_114.0.wav │ │ │ ├── n_JVT4IZI0WD_403.0_404.0.wav │ │ │ ├── n_JX26LM126I_153.0_154.0.wav │ │ │ ├── n_JYE9UKU6B8_47.0_48.0.wav │ │ │ ├── n_JZI5ZT251L_119.0_120.0.wav │ │ │ ├── n_K094QM69ZL_25.0_26.0.wav │ │ │ ├── n_K0WN1TQD95_217.0_218.0.wav │ │ │ ├── n_K15S0Q9XTR_375.0_376.0.wav │ │ │ ├── n_K47XMX5QV1_25.0_26.0.wav │ │ │ ├── n_K8X4X6NSK0_78.0_79.0.wav │ │ │ ├── n_KB8KYXVZP6_3.0_4.0.wav │ │ │ ├── n_KI9HV9W9LE_9.0_10.0.wav │ │ │ ├── n_KIQ8MRMBOX_0.0_1.0.wav │ │ │ ├── n_KKH1W0BIUJ_6.0_7.0.wav │ │ │ ├── n_KL7R0JYSI0_9.0_10.0.wav │ │ │ ├── n_KLYQ9WXH97_398.0_399.0.wav │ │ │ ├── n_KOY1L5KERV_1555.0_1556.0.wav │ │ │ ├── n_KQMH26JWBU_40.0_41.0.wav │ │ │ ├── n_KS0DKSI1I4_70.0_71.0.wav │ │ │ ├── n_KTZ1HTYTKZ_254.0_255.0.wav │ │ │ ├── n_KUMBL580ZV_353.0_354.0.wav │ │ │ ├── n_KXPT7Z0VVM_368.0_369.0.wav │ │ │ ├── n_KYV66B9WJ1_73.0_74.0.wav │ │ │ ├── n_KZQTZJRU9X_190.0_191.0.wav │ │ │ ├── n_KZVLBPHKXP_644.0_645.0.wav │ │ │ ├── n_L1JBOS8KT9_2.0_3.0.wav │ │ │ ├── n_L46L6RQU69_133.0_134.0.wav │ │ │ ├── n_L89ISQUOUL_144.0_145.0.wav │ │ │ ├── n_L8E31PV819_280.0_281.0.wav │ │ │ ├── n_L8X7K5HJ7E_348.0_349.0.wav │ │ │ ├── n_LB0Q98WT4D_149.0_150.0.wav │ │ │ └── n_LBSPUNWMJH_54.0_55.0.wav │ │ └── speech │ │ │ ├── s_WOSUYWSZ8W_8.0_9.0.wav │ │ │ ├── s_WQRJ6E7JTT_15.0_16.0.wav │ │ │ ├── s_WRZ6T95JN4_124.0_125.0.wav │ │ │ ├── s_X57TS62DN9_8.0_9.0.wav │ │ │ ├── s_X619ELD02H_19.0_20.0.wav │ │ │ ├── s_X8JF9RZMZ2_112.0_113.0.wav │ │ │ ├── s_XBD7QTOBY8_46.0_47.0.wav │ │ │ ├── s_XMY3DWQZVE_97.0_98.0.wav │ │ │ ├── s_XOWT3I8BS0_13.0_14.0.wav │ │ │ ├── s_XROYOHT6H9_26.0_27.0.wav │ │ │ ├── s_XT9W5UOSN9_586.0_587.0.wav │ │ │ ├── s_XWUIVH8D66_115.0_116.0.wav │ │ │ ├── s_XYJDI1HX0D_11.0_12.0.wav │ │ │ ├── s_Y1VOJ37M96_14.0_15.0.wav │ │ │ ├── s_Y3YTM0E9JT_231.0_232.0.wav │ │ │ ├── s_YEO5SB93T7_303.0_304.0.wav │ │ │ ├── s_YJ7M0500S4_84.0_85.0.wav │ │ │ ├── s_YR283WBWFN_222.0_223.0.wav │ │ │ ├── s_YTVB8DBH77_63.0_64.0.wav │ │ │ ├── s_YVT841J6D3_272.0_273.0.wav │ │ │ ├── s_YY61TWWN19_35.0_36.0.wav │ │ │ ├── s_Z1QTV2DXNV_942.0_943.0.wav │ │ │ ├── s_Z35XHX8ITY_22.0_23.0.wav │ │ │ ├── s_Z3H3HRYSNT_24.0_25.0.wav │ │ │ ├── s_Z5ZYNSTY3Y_69.0_70.0.wav │ │ │ ├── s_Z7N2VJ86N1_6.0_7.0.wav │ │ │ ├── s_Z8594V8SWQ_65.0_66.0.wav │ │ │ ├── s_Z8UQZR43T8_175.0_176.0.wav │ │ │ ├── s_Z9ZMEVVYJN_682.0_683.0.wav │ │ │ ├── s_ZDQ20R9I2T_12.0_13.0.wav │ │ │ ├── s_ZI8RH203IZ_33.0_34.0.wav │ │ │ ├── s_ZJ9NT05R04_85.0_86.0.wav │ │ │ ├── s_ZND7Q77JR3_137.0_138.0.wav │ │ │ ├── s_ZR4I5R4ZHS_25.0_26.0.wav │ │ │ ├── s_ZSTX9X681O_328.0_329.0.wav │ │ │ ├── s_ZU8JUIWZ5J_356.0_357.0.wav │ │ │ ├── s_ZUVDE5SEJ7_41.0_42.0.wav │ │ │ ├── s_ZV86T57WRX_17.0_18.0.wav │ │ │ ├── s_ZW67WQ8DTQ_192.0_193.0.wav │ │ │ └── s_ZWYNTU6HBR_29.0_30.0.wav │ ├── 5_sec_wav.wav │ ├── count.wav │ ├── diarizationExample.segments │ ├── diarizationExample.wav │ ├── scottish.segments │ ├── scottish.wav │ ├── svm_rbf_sm │ └── svm_rbf_smMEANS ├── test_feature_extraction.py └── test_segmentation.py ├── requirements.txt ├── setup.py └── tests ├── README.md ├── cmd_test_00.sh ├── cmd_test_01.sh ├── cmd_test_02.sh ├── cmd_test_02_B.sh ├── cmd_test_02_C.sh ├── cmd_test_03.sh ├── cmd_test_04.sh ├── cmd_test_05.sh ├── cmd_test_06.sh ├── cmd_test_07.sh ├── cmd_test_08.sh ├── cmd_test_09.sh ├── cmd_test_10.sh ├── cmd_test_11.sh ├── cmd_test_12_1.sh ├── cmd_test_12_2.sh ├── cmd_test_12_3.sh ├── cmd_test_12_4.sh ├── cmd_test_12_5.sh ├── cmd_test_12_6.sh ├── script_test_classifier.py ├── script_tests.py └── script_train_classifiers_all.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: tyiannak 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.pyc 3 | *.npy 4 | .idea 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # A Python library for audio feature extraction, classification, segmentation and applications 3 | 4 | *This is general info. Click [here](https://github.com/tyiannak/pyAudioAnalysis/wiki) for the complete wiki and [here](https://hackernoon.com/audio-handling-basics-how-to-process-audio-files-using-python-cli-jo283u3y) for a more generic intro to audio data handling* 5 | 6 | ## News 7 | * [2025-03-29] Check [oliver api repo](https://github.com/BehavioralSignalTechnologies/oliver_api) that demonstrates how to use [Behavioral Signals' Oliver API](https://oliver.behavioralsignals.com) to send speech data and retrieve predictions related to emotions and behaviors using Python code. Now [Behavioral Signals' Oliver API](https://oliver.behavioralsignals.com) also supports a Speaker Agnostic Deep Fake Detector. 8 | * [2021-08-06] [deep-audio-features](https://github.com/tyiannak/deep_audio_features) deep audio classification and feature extraction using CNNs and Pytorch 9 | * Check out [paura](https://github.com/tyiannak/paura) a Python script for realtime recording and analysis of audio data 10 | 11 | ## General 12 | pyAudioAnalysis is a Python library covering a wide range of audio analysis tasks. Through pyAudioAnalysis you can: 13 | * Extract audio *features* and representations (e.g. mfccs, spectrogram, chromagram) 14 | * *Train*, parameter tune and *evaluate* classifiers of audio segments 15 | * *Classify* unknown sounds 16 | * *Detect* audio events and exclude silence periods from long recordings 17 | * Perform *supervised segmentation* (joint segmentation - classification) 18 | * Perform *unsupervised segmentation* (e.g. speaker diarization) and extract audio *thumbnails* 19 | * Train and use *audio regression* models (example application: emotion recognition) 20 | * Apply dimensionality reduction to *visualize* audio data and content similarities 21 | 22 | ## Installation 23 | * Clone the source of this library: `git clone https://github.com/tyiannak/pyAudioAnalysis.git` 24 | * Install dependencies: `pip install -r ./requirements.txt ` 25 | * Install using pip: `pip install -e .` 26 | 27 | ## An audio classification example 28 | > More examples and detailed tutorials can be found [at the wiki](https://github.com/tyiannak/pyAudioAnalysis/wiki) 29 | 30 | pyAudioAnalysis provides easy-to-call wrappers to execute audio analysis tasks. Eg, this code first trains an audio segment classifier, given a set of WAV files stored in folders (each folder representing a different class) and then the trained classifier is used to classify an unknown audio WAV file 31 | 32 | ```python 33 | from pyAudioAnalysis import audioTrainTest as aT 34 | aT.extract_features_and_train(["classifierData/music","classifierData/speech"], 1.0, 1.0, aT.shortTermWindow, aT.shortTermStep, "svm", "svmSMtemp", False) 35 | aT.file_classification("data/doremi.wav", "svmSMtemp","svm") 36 | ``` 37 | 38 | >Result: 39 | (0.0, array([ 0.90156761, 0.09843239]), ['music', 'speech']) 40 | 41 | In addition, command-line support is provided for all functionalities. E.g. the following command extracts the spectrogram of an audio signal stored in a WAV file: `python audioAnalysis.py fileSpectrogram -i data/doremi.wav` 42 | 43 | ## Further reading 44 | 45 | Apart from this README file, to bettern understand how to use this library one should read the following: 46 | * [Audio Handling Basics: Process Audio Files In Command-Line or Python](https://hackernoon.com/audio-handling-basics-how-to-process-audio-files-using-python-cli-jo283u3y), if you want to learn how to handle audio files from command line, and some basic programming on audio signal processing. Start with that if you don't know anything about audio. 47 | * [Intro to Audio Analysis: Recognizing Sounds Using Machine Learning](https://hackernoon.com/intro-to-audio-analysis-recognizing-sounds-using-machine-learning-qy2r3ufl) This goes a bit deeper than the previous article, by providing a complete intro to theory and practice of audio feature extraction, classification and segmentation (includes many Python examples). 48 | * [The library's wiki](https://github.com/tyiannak/pyAudioAnalysis/wiki) 49 | * [How to Use Machine Learning to Color Your Lighting Based on Music Mood](https://hackernoon.com/how-to-use-machine-learning-to-color-your-lighting-based-on-music-mood-bi163u8l). An interesting use-case of using this lib to train a real-time music mood estimator. 50 | * A more general and theoretic description of the adopted methods (along with several experiments on particular use-cases) is presented [in this publication](http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0144610). *Please use the following citation when citing pyAudioAnalysis in your research work*: 51 | ```python 52 | @article{giannakopoulos2015pyaudioanalysis, 53 | title={pyAudioAnalysis: An Open-Source Python Library for Audio Signal Analysis}, 54 | author={Giannakopoulos, Theodoros}, 55 | journal={PloS one}, 56 | volume={10}, 57 | number={12}, 58 | year={2015}, 59 | publisher={Public Library of Science} 60 | } 61 | ``` 62 | 63 | For Matlab-related audio analysis material check [this book](http://www.amazon.com/Introduction-Audio-Analysis-MATLAB%C2%AE-Approach/dp/0080993885). 64 | 65 | ## Author 66 | 67 | 68 | [Theodoros Giannakopoulos](https://tyiannak.github.io), 69 | Principal Researcher of Multimodal Machine Learning at the [Multimedia Analysis Group of the Computational Intelligence Lab (MagCIL)](https://labs-repos.iit.demokritos.gr/MagCIL/index.html) of the Institute of Informatics and Telecommunications, of the National Center for Scientific Research "Demokritos" 70 | 71 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyiannak/pyAudioAnalysis/a246ebf4c553db49ed4400e3a902d39c89ec0043/icon.png -------------------------------------------------------------------------------- /pyAudioAnalysis/MidTermFeatures.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import os 3 | import time 4 | import glob 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import sys 8 | sys.path.insert(0, os.path.join( 9 | os.path.dirname(os.path.realpath(__file__)), "../")) 10 | from pyAudioAnalysis import utilities 11 | from pyAudioAnalysis import audioBasicIO 12 | from pyAudioAnalysis import ShortTermFeatures 13 | eps = 0.00000001 14 | 15 | """ Time-domain audio features """ 16 | 17 | 18 | def beat_extraction(short_features, window_size, plot=False): 19 | """ 20 | This function extracts an estimate of the beat rate for a musical signal. 21 | ARGUMENTS: 22 | - short_features: a np array (n_feats x numOfShortTermWindows) 23 | - window_size: window size in seconds 24 | RETURNS: 25 | - bpm: estimates of beats per minute 26 | - ratio: a confidence measure 27 | """ 28 | 29 | # Features that are related to the beat tracking task: 30 | selected_features = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 31 | 11, 12, 13, 14, 15, 16, 17, 18] 32 | 33 | max_beat_time = int(round(2.0 / window_size)) 34 | hist_all = np.zeros((max_beat_time,)) 35 | # for each feature 36 | for ii, i in enumerate(selected_features): 37 | # dif threshold (3 x Mean of Difs) 38 | dif_threshold = 2.0 * (np.abs(short_features[i, 0:-1] - 39 | short_features[i, 1::])).mean() 40 | if dif_threshold <= 0: 41 | dif_threshold = 0.0000000000000001 42 | # detect local maxima 43 | [pos1, _] = utilities.peakdet(short_features[i, :], dif_threshold) 44 | position_diffs = [] 45 | # compute histograms of local maxima changes 46 | for j in range(len(pos1)-1): 47 | position_diffs.append(pos1[j+1]-pos1[j]) 48 | histogram_times, histogram_edges = \ 49 | np.histogram(position_diffs, np.arange(0.5, max_beat_time + 1.5)) 50 | hist_centers = (histogram_edges[0:-1] + histogram_edges[1::]) / 2.0 51 | histogram_times = \ 52 | histogram_times.astype(float) / short_features.shape[1] 53 | hist_all += histogram_times 54 | if plot: 55 | plt.subplot(9, 2, ii + 1) 56 | plt.plot(short_features[i, :], 'k') 57 | for k in pos1: 58 | plt.plot(k, short_features[i, k], 'k*') 59 | f1 = plt.gca() 60 | f1.axes.get_xaxis().set_ticks([]) 61 | f1.axes.get_yaxis().set_ticks([]) 62 | 63 | if plot: 64 | plt.show(block=False) 65 | plt.figure() 66 | 67 | # Get beat as the argmax of the agregated histogram: 68 | max_indices = np.argmax(hist_all) 69 | bpms = 60 / (hist_centers * window_size) 70 | bpm = bpms[max_indices] 71 | # ... and the beat ratio: 72 | ratio = hist_all[max_indices] / (hist_all.sum() + eps) 73 | 74 | if plot: 75 | # filter out >500 beats from plotting: 76 | hist_all = hist_all[bpms < 500] 77 | bpms = bpms[bpms < 500] 78 | 79 | plt.plot(bpms, hist_all, 'k') 80 | plt.xlabel('Beats per minute') 81 | plt.ylabel('Freq Count') 82 | plt.show(block=True) 83 | 84 | return bpm, ratio 85 | 86 | 87 | def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step, 88 | short_window, short_step): 89 | """ 90 | Mid-term feature extraction 91 | """ 92 | 93 | short_features, short_feature_names = \ 94 | ShortTermFeatures.feature_extraction(signal, sampling_rate, 95 | short_window, short_step) 96 | 97 | n_stats = 2 98 | n_feats = len(short_features) 99 | #mid_window_ratio = int(round(mid_window / short_step)) 100 | mid_window_ratio = round((mid_window - 101 | (short_window - short_step)) / short_step) 102 | mt_step_ratio = int(round(mid_step / short_step)) 103 | 104 | mid_features, mid_feature_names = [], [] 105 | for i in range(n_stats * n_feats): 106 | mid_features.append([]) 107 | mid_feature_names.append("") 108 | 109 | # for each of the short-term features: 110 | for i in range(n_feats): 111 | cur_position = 0 112 | num_short_features = len(short_features[i]) 113 | mid_feature_names[i] = short_feature_names[i] + "_" + "mean" 114 | mid_feature_names[i + n_feats] = short_feature_names[i] + "_" + "std" 115 | 116 | while cur_position < num_short_features: 117 | end = cur_position + mid_window_ratio 118 | if end > num_short_features: 119 | end = num_short_features 120 | cur_st_feats = short_features[i][cur_position:end] 121 | 122 | mid_features[i].append(np.mean(cur_st_feats)) 123 | mid_features[i + n_feats].append(np.std(cur_st_feats)) 124 | cur_position += mt_step_ratio 125 | mid_features = np.array(mid_features) 126 | mid_features = np.nan_to_num(mid_features) 127 | return mid_features, short_features, mid_feature_names 128 | 129 | 130 | """ Feature Extraction Wrappers 131 | - The first two feature extraction wrappers are used to extract 132 | long-term averaged audio features for a list of WAV files stored in a 133 | given category. 134 | It is important to note that, one single feature is extracted per WAV 135 | file (not the whole sequence of feature vectors) 136 | 137 | """ 138 | 139 | 140 | def directory_feature_extraction(folder_path, mid_window, mid_step, 141 | short_window, short_step, 142 | compute_beat=True): 143 | """ 144 | This function extracts the mid-term features of the WAVE files of a 145 | particular folder. 146 | 147 | The resulting feature vector is extracted by long-term averaging the 148 | mid-term features. 149 | Therefore ONE FEATURE VECTOR is extracted for each WAV file. 150 | 151 | ARGUMENTS: 152 | - folder_path: the path of the WAVE directory 153 | - mid_window, mid_step: mid-term window and step (in seconds) 154 | - short_window, short_step: short-term window and step (in seconds) 155 | """ 156 | 157 | mid_term_features = np.array([]) 158 | process_times = [] 159 | 160 | types = ('*.wav', '*.aif', '*.aiff', '*.mp3', '*.au', '*.ogg') 161 | wav_file_list = [] 162 | for files in types: 163 | wav_file_list.extend(glob.glob(os.path.join(folder_path, files))) 164 | 165 | wav_file_list = sorted(wav_file_list) 166 | wav_file_list2, mid_feature_names = [], [] 167 | for i, file_path in enumerate(wav_file_list): 168 | print("Analyzing file {0:d} of {1:d}: {2:s}".format(i + 1, 169 | len(wav_file_list), 170 | file_path)) 171 | if os.stat(file_path).st_size == 0: 172 | print(" (EMPTY FILE -- SKIPPING)") 173 | continue 174 | sampling_rate, signal = audioBasicIO.read_audio_file(file_path) 175 | if sampling_rate == 0: 176 | continue 177 | 178 | t1 = time.time() 179 | signal = audioBasicIO.stereo_to_mono(signal) 180 | if signal.shape[0] < float(sampling_rate)/5: 181 | print(" (AUDIO FILE TOO SMALL - SKIPPING)") 182 | continue 183 | wav_file_list2.append(file_path) 184 | if compute_beat: 185 | mid_features, short_features, mid_feature_names = \ 186 | mid_feature_extraction(signal, sampling_rate, 187 | round(mid_window * sampling_rate), 188 | round(mid_step * sampling_rate), 189 | round(sampling_rate * short_window), 190 | round(sampling_rate * short_step)) 191 | beat, beat_conf = beat_extraction(short_features, short_step) 192 | else: 193 | mid_features, _, mid_feature_names = \ 194 | mid_feature_extraction(signal, sampling_rate, 195 | round(mid_window * sampling_rate), 196 | round(mid_step * sampling_rate), 197 | round(sampling_rate * short_window), 198 | round(sampling_rate * short_step)) 199 | 200 | mid_features = np.transpose(mid_features) 201 | mid_features = mid_features.mean(axis=0) 202 | # long term averaging of mid-term statistics 203 | if (not np.isnan(mid_features).any()) and \ 204 | (not np.isinf(mid_features).any()): 205 | if compute_beat: 206 | mid_features = np.append(mid_features, beat) 207 | mid_features = np.append(mid_features, beat_conf) 208 | mid_feature_names += ["bpm","ratio"] 209 | if len(mid_term_features) == 0: 210 | # append feature vector 211 | mid_term_features = mid_features 212 | else: 213 | mid_term_features = np.vstack((mid_term_features, mid_features)) 214 | t2 = time.time() 215 | duration = float(len(signal)) / sampling_rate 216 | process_times.append((t2 - t1) / duration) 217 | if len(process_times) > 0: 218 | print("Feature extraction complexity ratio: " 219 | "{0:.1f} x realtime".format((1.0 / 220 | np.mean(np.array(process_times))))) 221 | return mid_term_features, wav_file_list2, mid_feature_names 222 | 223 | 224 | def multiple_directory_feature_extraction(path_list, mid_window, mid_step, 225 | short_window, short_step, 226 | compute_beat=False): 227 | """ 228 | Same as dirWavFeatureExtraction, but instead of a single dir it 229 | takes a list of paths as input and returns a list of feature matrices. 230 | EXAMPLE: 231 | [features, classNames] = 232 | a.dirsWavFeatureExtraction(['audioData/classSegmentsRec/noise', 233 | 'audioData/classSegmentsRec/speech', 234 | 'audioData/classSegmentsRec/brush-teeth', 235 | 'audioData/classSegmentsRec/shower'], 1, 236 | 1, 0.02, 0.02); 237 | 238 | It can be used during the training process of a classification model , 239 | in order to get feature matrices from various audio classes (each stored in 240 | a separate path) 241 | """ 242 | 243 | # feature extraction for each class: 244 | features = [] 245 | class_names = [] 246 | file_names = [] 247 | for i, d in enumerate(path_list): 248 | f, fn, feature_names = \ 249 | directory_feature_extraction(d, mid_window, mid_step, 250 | short_window, short_step, 251 | compute_beat=compute_beat) 252 | if f.shape[0] > 0: 253 | # if at least one audio file has been found in the provided folder: 254 | features.append(f) 255 | file_names.append(fn) 256 | if d[-1] == os.sep: 257 | class_names.append(d.split(os.sep)[-2]) 258 | else: 259 | class_names.append(d.split(os.sep)[-1]) 260 | return features, class_names, file_names 261 | 262 | 263 | def directory_feature_extraction_no_avg(folder_path, mid_window, mid_step, 264 | short_window, short_step): 265 | """ 266 | This function extracts the mid-term features of the WAVE 267 | files of a particular folder without averaging each file. 268 | 269 | ARGUMENTS: 270 | - folder_path: the path of the WAVE directory 271 | - mid_window, mid_step: mid-term window and step (in seconds) 272 | - short_window, short_step: short-term window and step (in seconds) 273 | RETURNS: 274 | - X: A feature matrix 275 | - Y: A matrix of file labels 276 | - filenames: 277 | """ 278 | 279 | wav_file_list = [] 280 | signal_idx = np.array([]) 281 | mid_features = np.array([]) 282 | types = ('*.wav', '*.aif', '*.aiff', '*.ogg') 283 | for files in types: 284 | wav_file_list.extend(glob.glob(os.path.join(folder_path, files))) 285 | 286 | wav_file_list = sorted(wav_file_list) 287 | 288 | for i, file_path in enumerate(wav_file_list): 289 | sampling_rate, signal = audioBasicIO.read_audio_file(file_path) 290 | if sampling_rate == 0: 291 | continue 292 | signal = audioBasicIO.stereo_to_mono(signal) 293 | mid_feature_vector, _, _ = \ 294 | mid_feature_extraction(signal, sampling_rate, 295 | round(mid_window * sampling_rate), 296 | round(mid_step * sampling_rate), 297 | round(sampling_rate * short_window), 298 | round(sampling_rate * short_step)) 299 | 300 | mid_feature_vector = np.transpose(mid_feature_vector) 301 | if len(mid_features) == 0: # append feature vector 302 | mid_features = mid_feature_vector 303 | signal_idx = np.zeros((mid_feature_vector.shape[0], )) 304 | else: 305 | mid_features = np.vstack((mid_features, mid_feature_vector)) 306 | signal_idx = np.append(signal_idx, i * 307 | np.ones((mid_feature_vector.shape[0], ))) 308 | 309 | return mid_features, signal_idx, wav_file_list 310 | 311 | 312 | """ 313 | The following two feature extraction wrappers extract features for given audio 314 | files, however NO LONG-TERM AVERAGING is performed. Therefore, the output for 315 | each audio file is NOT A SINGLE FEATURE VECTOR but a whole feature matrix. 316 | 317 | Also, another difference between the following two wrappers and the previous 318 | is that they NO LONG-TERM AVERAGING IS PERFORMED. In other words, the WAV 319 | files in these functions are not used as uniform samples that need to be 320 | averaged but as sequences 321 | """ 322 | 323 | 324 | def mid_feature_extraction_to_file(file_path, mid_window, mid_step, 325 | short_window, short_step, output_file, 326 | store_short_features=False, store_csv=False, 327 | plot=False): 328 | """ 329 | This function is used as a wrapper to: 330 | a) read the content of a WAV file 331 | b) perform mid-term feature extraction on that signal 332 | c) write the mid-term feature sequences to a np file 333 | d) optionally write contents to csv file as well 334 | e) optionally write short-term features in csv and np file 335 | """ 336 | sampling_rate, signal = audioBasicIO.read_audio_file(file_path) 337 | signal = audioBasicIO.stereo_to_mono(signal) 338 | mid_features, short_features, _ = \ 339 | mid_feature_extraction(signal, sampling_rate, 340 | round(sampling_rate * mid_window), 341 | round(sampling_rate * mid_step), 342 | round(sampling_rate * short_window), 343 | round(sampling_rate * short_step)) 344 | if store_short_features: 345 | # save st features to np file 346 | np.save(output_file + "_st", short_features) 347 | if plot: 348 | print("Short-term np file: " + output_file + "_st.npy saved") 349 | if store_csv: 350 | # store st features to CSV file 351 | np.savetxt(output_file + "_st.csv", short_features.T, delimiter=",") 352 | if plot: 353 | print("Short-term CSV file: " + output_file + "_st.csv saved") 354 | 355 | # save mt features to np file 356 | np.save(output_file + "_mt", mid_features) 357 | if plot: 358 | print("Mid-term np file: " + output_file + "_mt.npy saved") 359 | if store_csv: 360 | np.savetxt(output_file + "_mt.csv", mid_features.T, delimiter=",") 361 | if plot: 362 | print("Mid-term CSV file: " + output_file + "_mt.csv saved") 363 | 364 | 365 | def mid_feature_extraction_file_dir(folder_path, mid_window, mid_step, 366 | short_window, short_step, 367 | store_short_features=False, store_csv=False, 368 | plot=False): 369 | types = (folder_path + os.sep + '*.wav',) 370 | files_list = [] 371 | for t in types: 372 | files_list.extend(glob.glob(t)) 373 | for f in files_list: 374 | output_path = f 375 | mid_feature_extraction_to_file(f, mid_window, mid_step, short_window, 376 | short_step, output_path, 377 | store_short_features, store_csv, plot) 378 | -------------------------------------------------------------------------------- /pyAudioAnalysis/ShortTermFeatures.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import math 3 | import numpy as np 4 | import sys 5 | from scipy.fftpack import fft 6 | import matplotlib.pyplot as plt 7 | from scipy.signal import lfilter 8 | from scipy.fftpack.realtransforms import dct 9 | from tqdm import tqdm 10 | 11 | eps = sys.float_info.epsilon 12 | 13 | 14 | def dc_normalize(sig_array): 15 | """Removes DC and normalizes to -1, 1 range""" 16 | sig_array_norm = sig_array.copy() 17 | sig_array_norm -= sig_array_norm.mean() 18 | sig_array_norm /= abs(sig_array_norm).max() + 1e-10 19 | return sig_array_norm 20 | 21 | 22 | def zero_crossing_rate(frame): 23 | """Computes zero crossing rate of frame""" 24 | count = len(frame) 25 | count_zero = np.sum(np.abs(np.diff(np.sign(frame)))) / 2 26 | return np.float64(count_zero) / np.float64(count - 1.0) 27 | 28 | 29 | def energy(frame): 30 | """Computes signal energy of frame""" 31 | return np.sum(frame ** 2) / np.float64(len(frame)) 32 | 33 | 34 | def energy_entropy(frame, n_short_blocks=10): 35 | """Computes entropy of energy""" 36 | # total frame energy 37 | frame_energy = np.sum(frame ** 2) 38 | frame_length = len(frame) 39 | sub_win_len = int(np.floor(frame_length / n_short_blocks)) 40 | if frame_length != sub_win_len * n_short_blocks: 41 | frame = frame[0:sub_win_len * n_short_blocks] 42 | 43 | # sub_wins is of size [n_short_blocks x L] 44 | sub_wins = frame.reshape(sub_win_len, n_short_blocks, order='F').copy() 45 | 46 | # Compute normalized sub-frame energies: 47 | s = np.sum(sub_wins ** 2, axis=0) / (frame_energy + eps) 48 | 49 | # Compute entropy of the normalized sub-frame energies: 50 | entropy = -np.sum(s * np.log2(s + eps)) 51 | return entropy 52 | 53 | 54 | """ Frequency-domain audio features """ 55 | 56 | 57 | def spectral_centroid_spread(fft_magnitude, sampling_rate): 58 | """Computes spectral centroid of frame (given abs(FFT))""" 59 | ind = (np.arange(1, len(fft_magnitude) + 1)) * \ 60 | (sampling_rate / (2.0 * len(fft_magnitude))) 61 | 62 | Xt = fft_magnitude.copy() 63 | Xt_max = Xt.max() 64 | if Xt_max == 0: 65 | Xt = Xt / eps 66 | else: 67 | Xt = Xt / Xt_max 68 | 69 | NUM = np.sum(ind * Xt) 70 | DEN = np.sum(Xt) + eps 71 | 72 | # Centroid: 73 | centroid = (NUM / DEN) 74 | 75 | # Spread: 76 | spread = np.sqrt(np.sum(((ind - centroid) ** 2) * Xt) / DEN) 77 | 78 | # Normalize: 79 | centroid = centroid / (sampling_rate / 2.0) 80 | spread = spread / (sampling_rate / 2.0) 81 | 82 | return centroid, spread 83 | 84 | 85 | def spectral_entropy(signal, n_short_blocks=10): 86 | """Computes the spectral entropy""" 87 | # number of frame samples 88 | num_frames = len(signal) 89 | 90 | # total spectral energy 91 | total_energy = np.sum(signal ** 2) 92 | 93 | # length of sub-frame 94 | sub_win_len = int(np.floor(num_frames / n_short_blocks)) 95 | if num_frames != sub_win_len * n_short_blocks: 96 | signal = signal[0:sub_win_len * n_short_blocks] 97 | 98 | # define sub-frames (using matrix reshape) 99 | sub_wins = signal.reshape(sub_win_len, n_short_blocks, order='F').copy() 100 | 101 | # compute spectral sub-energies 102 | s = np.sum(sub_wins ** 2, axis=0) / (total_energy + eps) 103 | 104 | # compute spectral entropy 105 | entropy = -np.sum(s * np.log2(s + eps)) 106 | 107 | return entropy 108 | 109 | 110 | def spectral_flux(fft_magnitude, previous_fft_magnitude): 111 | """ 112 | Computes the spectral flux feature of the current frame 113 | ARGUMENTS: 114 | fft_magnitude: the abs(fft) of the current frame 115 | previous_fft_magnitude: the abs(fft) of the previous frame 116 | """ 117 | # compute the spectral flux as the sum of square distances: 118 | fft_sum = np.sum(fft_magnitude + eps) 119 | previous_fft_sum = np.sum(previous_fft_magnitude + eps) 120 | sp_flux = np.sum( 121 | (fft_magnitude / fft_sum - previous_fft_magnitude / 122 | previous_fft_sum) ** 2) 123 | 124 | return sp_flux 125 | 126 | 127 | def spectral_rolloff(signal, c): 128 | """Computes spectral roll-off""" 129 | energy = np.sum(signal ** 2) 130 | fft_length = len(signal) 131 | threshold = c * energy 132 | # Ffind the spectral rolloff as the frequency position 133 | # where the respective spectral energy is equal to c*totalEnergy 134 | cumulative_sum = np.cumsum(signal ** 2) + eps 135 | a = np.nonzero(cumulative_sum > threshold)[0] 136 | if len(a) > 0: 137 | sp_rolloff = np.float64(a[0]) / (float(fft_length)) 138 | else: 139 | sp_rolloff = 0.0 140 | return sp_rolloff 141 | 142 | 143 | def harmonic(frame, sampling_rate): 144 | """ 145 | Computes harmonic ratio and pitch 146 | """ 147 | m = np.round(0.016 * sampling_rate) - 1 148 | r = np.correlate(frame, frame, mode='full') 149 | 150 | g = r[len(frame) - 1] 151 | r = r[len(frame):-1] 152 | 153 | # estimate m0 (as the first zero crossing of R) 154 | [a, ] = np.nonzero(np.diff(np.sign(r))) 155 | 156 | if len(a) == 0: 157 | m0 = len(r) - 1 158 | else: 159 | m0 = a[0] 160 | if m > len(r): 161 | m = len(r) - 1 162 | 163 | gamma = np.zeros((m), dtype=np.float64) 164 | cumulative_sum = np.cumsum(frame ** 2) 165 | gamma[m0:m] = r[m0:m] / (np.sqrt((g * cumulative_sum[m:m0:-1])) + eps) 166 | 167 | zcr = zero_crossing_rate(gamma) 168 | 169 | if zcr > 0.15: 170 | hr = 0.0 171 | f0 = 0.0 172 | else: 173 | if len(gamma) == 0: 174 | hr = 1.0 175 | blag = 0.0 176 | gamma = np.zeros((m), dtype=np.float64) 177 | else: 178 | hr = np.max(gamma) 179 | blag = np.argmax(gamma) 180 | 181 | # Get fundamental frequency: 182 | f0 = sampling_rate / (blag + eps) 183 | if f0 > 5000: 184 | f0 = 0.0 185 | if hr < 0.1: 186 | f0 = 0.0 187 | 188 | return hr, f0 189 | 190 | 191 | def mfcc_filter_banks(sampling_rate, num_fft, lowfreq=133.33, linc=200 / 3, 192 | logsc=1.0711703, num_lin_filt=13, num_log_filt=27): 193 | """ 194 | Computes the triangular filterbank for MFCC computation 195 | (used in the stFeatureExtraction function before the stMFCC function call) 196 | This function is taken from the scikits.talkbox library (MIT Licence): 197 | https://pypi.python.org/pypi/scikits.talkbox 198 | """ 199 | 200 | if sampling_rate < 8000: 201 | nlogfil = 5 202 | 203 | # Total number of filters 204 | num_filt_total = num_lin_filt + num_log_filt 205 | 206 | # Compute frequency points of the triangle: 207 | frequencies = np.zeros(num_filt_total + 2) 208 | frequencies[:num_lin_filt] = lowfreq + np.arange(num_lin_filt) * linc 209 | frequencies[num_lin_filt:] = frequencies[num_lin_filt - 1] * logsc ** \ 210 | np.arange(1, num_log_filt + 3) 211 | heights = 2. / (frequencies[2:] - frequencies[0:-2]) 212 | 213 | # Compute filterbank coeff (in fft domain, in bins) 214 | fbank = np.zeros((num_filt_total, num_fft)) 215 | nfreqs = np.arange(num_fft) / (1. * num_fft) * sampling_rate 216 | 217 | for i in range(num_filt_total): 218 | low_freqs = frequencies[i] 219 | cent_freqs = frequencies[i + 1] 220 | high_freqs = frequencies[i + 2] 221 | 222 | lid = np.arange(np.floor(low_freqs * num_fft / sampling_rate) + 1, 223 | np.floor(cent_freqs * num_fft / sampling_rate) + 1, 224 | dtype=int) 225 | lslope = heights[i] / (cent_freqs - low_freqs) 226 | rid = np.arange(np.floor(cent_freqs * num_fft / sampling_rate) + 1, 227 | np.floor(high_freqs * num_fft / sampling_rate) + 1, 228 | dtype=int) 229 | rslope = heights[i] / (high_freqs - cent_freqs) 230 | fbank[i][lid] = lslope * (nfreqs[lid] - low_freqs) 231 | fbank[i][rid] = rslope * (high_freqs - nfreqs[rid]) 232 | 233 | return fbank, frequencies 234 | 235 | 236 | def mfcc(fft_magnitude, fbank, num_mfcc_feats): 237 | """ 238 | Computes the MFCCs of a frame, given the fft mag 239 | 240 | ARGUMENTS: 241 | fft_magnitude: fft magnitude abs(FFT) 242 | fbank: filter bank (see mfccInitFilterBanks) 243 | RETURN 244 | ceps: MFCCs (13 element vector) 245 | 246 | Note: MFCC calculation is, in general, taken from the 247 | scikits.talkbox library (MIT Licence), 248 | # with a small number of modifications to make it more 249 | compact and suitable for the pyAudioAnalysis Lib 250 | """ 251 | 252 | mspec = np.log10(np.dot(fft_magnitude, fbank.T) + eps) 253 | ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:num_mfcc_feats] 254 | return ceps 255 | 256 | 257 | def chroma_features_init(num_fft, sampling_rate): 258 | """ 259 | This function initializes the chroma matrices used in the calculation 260 | of the chroma features 261 | """ 262 | freqs = np.array([((f + 1) * sampling_rate) / 263 | (2 * num_fft) for f in range(num_fft)]) 264 | cp = 27.50 265 | num_chroma = np.round(12.0 * np.log2(freqs / cp)).astype(int) 266 | 267 | num_freqs_per_chroma = np.zeros((num_chroma.shape[0],)) 268 | 269 | unique_chroma = np.unique(num_chroma) 270 | for u in unique_chroma: 271 | idx = np.nonzero(num_chroma == u) 272 | num_freqs_per_chroma[idx] = idx[0].shape 273 | 274 | return num_chroma, num_freqs_per_chroma 275 | 276 | 277 | def chroma_features(signal, sampling_rate, num_fft): 278 | # TODO: 1 complexity 279 | # TODO: 2 bug with large windows 280 | 281 | num_chroma, num_freqs_per_chroma = \ 282 | chroma_features_init(num_fft, sampling_rate) 283 | chroma_names = ['A', 'A#', 'B', 'C', 'C#', 'D', 284 | 'D#', 'E', 'F', 'F#', 'G', 'G#'] 285 | spec = signal ** 2 286 | if num_chroma.max() < num_chroma.shape[0]: 287 | C = np.zeros((num_chroma.shape[0],)) 288 | C[num_chroma] = spec 289 | C /= num_freqs_per_chroma[num_chroma] 290 | else: 291 | I = np.nonzero(num_chroma > num_chroma.shape[0])[0][0] 292 | C = np.zeros((num_chroma.shape[0],)) 293 | C[num_chroma[0:I - 1]] = spec 294 | C /= num_freqs_per_chroma 295 | final_matrix = np.zeros((12, 1)) 296 | newD = int(np.ceil(C.shape[0] / 12.0) * 12) 297 | C2 = np.zeros((newD,)) 298 | C2[0:C.shape[0]] = C 299 | C2 = C2.reshape(int(C2.shape[0] / 12), 12) 300 | # for i in range(12): 301 | # finalC[i] = np.sum(C[i:C.shape[0]:12]) 302 | final_matrix = np.sum(C2, axis=0).reshape(1, -1).T 303 | 304 | spec_sum = spec.sum() 305 | if spec_sum == 0: 306 | final_matrix /= eps 307 | else: 308 | final_matrix /= spec_sum 309 | 310 | # ax = plt.gca() 311 | # plt.hold(False) 312 | # plt.plot(finalC) 313 | # ax.set_xticks(range(len(chromaNames))) 314 | # ax.set_xticklabels(chromaNames) 315 | # xaxis = np.arange(0, 0.02, 0.01); 316 | # ax.set_yticks(range(len(xaxis))) 317 | # ax.set_yticklabels(xaxis) 318 | # plt.show(block=False) 319 | # plt.draw() 320 | 321 | return chroma_names, final_matrix 322 | 323 | 324 | def chromagram(signal, sampling_rate, window, step, plot=False, 325 | show_progress=False): 326 | """ 327 | Short-term FFT mag for spectogram estimation: 328 | Returns: 329 | a np array (num_fft x numOfShortTermWindows) 330 | ARGUMENTS: 331 | signal: the input signal samples 332 | sampling_rate: the sampling freq (in Hz) 333 | window: the short-term window size (in samples) 334 | step: the short-term window step (in samples) 335 | plot: flag, 1 if results are to be ploted 336 | RETURNS: 337 | """ 338 | window = int(window) 339 | step = int(step) 340 | signal = np.double(signal) 341 | signal = signal / (2.0 ** 15) 342 | signal = dc_normalize(signal) 343 | 344 | num_samples = len(signal) # total number of signals 345 | count_fr = 0 346 | num_fft = int(window / 2) 347 | chromogram = np.zeros((int((num_samples-step-window) / step) + 1, 12), 348 | dtype=np.float64) 349 | for cur_p in tqdm(range(window, num_samples - step, step), 350 | disable=not show_progress): 351 | count_fr += 1 352 | x = signal[cur_p:cur_p + window] 353 | X = abs(fft(x)) 354 | X = X[0:num_fft] 355 | X = X / len(X) 356 | chroma_names, chroma_feature_matrix = chroma_features(X, sampling_rate, 357 | num_fft) 358 | chroma_feature_matrix = chroma_feature_matrix[:, 0] 359 | chromogram[count_fr-1, :] = chroma_feature_matrix.T 360 | freq_axis = chroma_names 361 | time_axis = [(t * step) / sampling_rate 362 | for t in range(chromogram.shape[0])] 363 | 364 | if plot: 365 | fig, ax = plt.subplots() 366 | chromogram_plot = chromogram.transpose()[::-1, :] 367 | ratio = int(chromogram_plot.shape[1] / (3 * chromogram_plot.shape[0])) 368 | if ratio < 1: 369 | ratio = 1 370 | chromogram_plot = np.repeat(chromogram_plot, ratio, axis=0) 371 | imgplot = plt.imshow(chromogram_plot) 372 | 373 | ax.set_yticks(range(int(ratio / 2), len(freq_axis) * ratio, ratio)) 374 | ax.set_yticklabels(freq_axis[::-1]) 375 | t_step = int(count_fr / 3) 376 | time_ticks = range(0, count_fr, t_step) 377 | time_ticks_labels = ['%.2f' % (float(t * step) / sampling_rate) 378 | for t in time_ticks] 379 | ax.set_xticks(time_ticks) 380 | ax.set_xticklabels(time_ticks_labels) 381 | ax.set_xlabel('time (secs)') 382 | imgplot.set_cmap('jet') 383 | plt.colorbar() 384 | plt.show() 385 | 386 | return chromogram, time_axis, freq_axis 387 | 388 | 389 | def spectrogram(signal, sampling_rate, window, step, plot=False, 390 | show_progress=False): 391 | """ 392 | Short-term FFT mag for spectogram estimation: 393 | Returns: 394 | a np array (numOfShortTermWindows x num_fft) 395 | ARGUMENTS: 396 | signal: the input signal samples 397 | sampling_rate: the sampling freq (in Hz) 398 | window: the short-term window size (in samples) 399 | step: the short-term window step (in samples) 400 | plot: flag, 1 if results are to be ploted 401 | show_progress flag for showing progress using tqdm 402 | RETURNS: 403 | """ 404 | window = int(window) 405 | step = int(step) 406 | signal = np.double(signal) 407 | signal = signal / (2.0 ** 15) 408 | signal = dc_normalize(signal) 409 | 410 | num_samples = len(signal) # total number of signals 411 | count_fr = 0 412 | num_fft = int(window / 2) 413 | specgram = np.zeros((int((num_samples-window) / step) + 1, num_fft), 414 | dtype=np.float64) 415 | for cur_p in tqdm(range(window, num_samples - window + 1, step), 416 | disable=not show_progress): 417 | count_fr += 1 418 | x = signal[cur_p:cur_p + window] 419 | X = abs(fft(x)) 420 | X = X[0:num_fft] 421 | X = X / len(X) 422 | specgram[count_fr-1, :] = X 423 | 424 | freq_axis = [float((f + 1) * sampling_rate) / (2 * num_fft) 425 | for f in range(specgram.shape[1])] 426 | time_axis = [float(t * step) / sampling_rate 427 | for t in range(specgram.shape[0])] 428 | 429 | if plot: 430 | fig, ax = plt.subplots() 431 | imgplot = plt.imshow(specgram.transpose()[::-1, :]) 432 | fstep = int(num_fft / 5.0) 433 | frequency_ticks = range(0, int(num_fft) + fstep, fstep) 434 | frequency_tick_labels = \ 435 | [str(sampling_rate / 2 - 436 | int((f * sampling_rate) / (2 * num_fft))) 437 | for f in frequency_ticks] 438 | ax.set_yticks(frequency_ticks) 439 | ax.set_yticklabels(frequency_tick_labels) 440 | t_step = int(count_fr / 3) 441 | time_ticks = range(0, count_fr, t_step) 442 | time_ticks_labels = \ 443 | ['%.2f' % (float(t * step) / sampling_rate) for t in time_ticks] 444 | ax.set_xticks(time_ticks) 445 | ax.set_xticklabels(time_ticks_labels) 446 | ax.set_xlabel('time (secs)') 447 | ax.set_ylabel('freq (Hz)') 448 | imgplot.set_cmap('jet') 449 | plt.colorbar() 450 | plt.show() 451 | print(specgram.shape) 452 | return specgram, time_axis, freq_axis 453 | 454 | 455 | # TODO 456 | def speed_feature(signal, sampling_rate, window, step): 457 | signal = np.double(signal) 458 | signal = signal / (2.0 ** 15) 459 | signal = dc_normalize(signal) 460 | 461 | num_samples = len(signal) # total number of signals 462 | cur_p = 0 463 | count_fr = 0 464 | 465 | lowfreq = 133.33 466 | linsc = 200 / 3. 467 | logsc = 1.0711703 468 | nlinfil = 13 469 | nlogfil = 27 470 | n_mfcc_feats = 13 471 | nfil = nlinfil + nlogfil 472 | num_fft = window / 2 473 | if sampling_rate < 8000: 474 | nlogfil = 5 475 | nfil = nlinfil + nlogfil 476 | num_fft = window / 2 477 | 478 | # compute filter banks for mfcc: 479 | fbank, freqs = mfcc_filter_banks(sampling_rate, num_fft, lowfreq, linsc, 480 | logsc, nlinfil, nlogfil) 481 | 482 | n_time_spectral_feats = 8 483 | n_harmonic_feats = 1 484 | n_total_feats = n_time_spectral_feats + n_mfcc_feats + n_harmonic_feats 485 | # st_features = np.array([], dtype=np.float64) 486 | st_features = [] 487 | 488 | while cur_p + window - 1 < num_samples: 489 | count_fr += 1 490 | x = signal[cur_p:cur_p + window] 491 | cur_p = cur_p + step 492 | fft_magnitude = abs(fft(x)) 493 | fft_magnitude = fft_magnitude[0:num_fft] 494 | fft_magnitude = fft_magnitude / len(fft_magnitude) 495 | Ex = 0.0 496 | El = 0.0 497 | fft_magnitude[0:4] = 0 498 | # M = np.round(0.016 * fs) - 1 499 | # R = np.correlate(frame, frame, mode='full') 500 | st_features.append(harmonic(x, sampling_rate)) 501 | # for i in range(len(X)): 502 | # if (i < (len(X) / 8)) and (i > (len(X)/40)): 503 | # Ex += X[i]*X[i] 504 | # El += X[i]*X[i] 505 | # st_features.append(Ex / El) 506 | # st_features.append(np.argmax(X)) 507 | # if curFV[n_time_spectral_feats+n_mfcc_feats+1]>0: 508 | # print curFV[n_time_spectral_feats+n_mfcc_feats], 509 | # curFV[n_time_ 510 | # spectral_feats+n_mfcc_feats+1] 511 | return np.array(st_features) 512 | 513 | 514 | def phormants(x, sampling_rate): 515 | N = len(x) 516 | w = np.hamming(N) 517 | 518 | # Apply window and high pass filter. 519 | x1 = x * w 520 | x1 = lfilter([1], [1., 0.63], x1) 521 | 522 | # Get LPC. 523 | ncoeff = 2 + sampling_rate / 1000 524 | A, e, k = lpc(x1, ncoeff) 525 | # A, e, k = lpc(x1, 8) 526 | 527 | # Get roots. 528 | rts = np.roots(A) 529 | rts = [r for r in rts if np.imag(r) >= 0] 530 | 531 | # Get angles. 532 | angz = np.arctan2(np.imag(rts), np.real(rts)) 533 | 534 | # Get frequencies. 535 | frqs = sorted(angz * (sampling_rate / (2 * math.pi))) 536 | 537 | return frqs 538 | 539 | 540 | """ Windowing and feature extraction """ 541 | 542 | 543 | def feature_extraction(signal, sampling_rate, window, step, deltas=True): 544 | """ 545 | This function implements the shor-term windowing process. 546 | For each short-term window a set of features is extracted. 547 | This results to a sequence of feature vectors, stored in a np matrix. 548 | 549 | ARGUMENTS 550 | signal: the input signal samples 551 | sampling_rate: the sampling freq (in Hz) 552 | window: the short-term window size (in samples) 553 | step: the short-term window step (in samples) 554 | deltas: (opt) True/False if delta features are to be 555 | computed 556 | RETURNS 557 | features (numpy.ndarray): contains features 558 | (n_feats x numOfShortTermWindows) 559 | feature_names (python list): contains feature names 560 | (n_feats x numOfShortTermWindows) 561 | """ 562 | 563 | window = int(window) 564 | step = int(step) 565 | 566 | # signal normalization 567 | signal = np.double(signal) 568 | signal = signal / (2.0 ** 15) 569 | 570 | signal = dc_normalize(signal) 571 | 572 | number_of_samples = len(signal) # total number of samples 573 | current_position = 0 574 | count_fr = 0 575 | num_fft = int(window / 2) 576 | 577 | # compute the triangular filter banks used in the mfcc calculation 578 | fbank, freqs = mfcc_filter_banks(sampling_rate, num_fft) 579 | 580 | n_time_spectral_feats = 8 581 | n_harmonic_feats = 0 582 | n_mfcc_feats = 13 583 | n_chroma_feats = 13 584 | n_total_feats = n_time_spectral_feats + n_mfcc_feats + n_harmonic_feats + \ 585 | n_chroma_feats 586 | # n_total_feats = n_time_spectral_feats + n_mfcc_feats + 587 | # n_harmonic_feats 588 | 589 | # define list of feature names 590 | feature_names = ["zcr", "energy", "energy_entropy"] 591 | feature_names += ["spectral_centroid", "spectral_spread"] 592 | feature_names.append("spectral_entropy") 593 | feature_names.append("spectral_flux") 594 | feature_names.append("spectral_rolloff") 595 | feature_names += ["mfcc_{0:d}".format(mfcc_i) 596 | for mfcc_i in range(1, n_mfcc_feats + 1)] 597 | feature_names += ["chroma_{0:d}".format(chroma_i) 598 | for chroma_i in range(1, n_chroma_feats)] 599 | feature_names.append("chroma_std") 600 | 601 | # add names for delta features: 602 | if deltas: 603 | feature_names_2 = feature_names + ["delta " + f for f in feature_names] 604 | feature_names = feature_names_2 605 | 606 | features = [] 607 | # for each short-term window to end of signal 608 | while current_position + window - 1 < number_of_samples: 609 | count_fr += 1 610 | # get current window 611 | x = signal[current_position:current_position + window] 612 | 613 | # update window position 614 | current_position = current_position + step 615 | 616 | # get fft magnitude 617 | fft_magnitude = abs(fft(x)) 618 | 619 | # normalize fft 620 | fft_magnitude = fft_magnitude[0:num_fft] 621 | fft_magnitude = fft_magnitude / len(fft_magnitude) 622 | 623 | # keep previous fft mag (used in spectral flux) 624 | if count_fr == 1: 625 | fft_magnitude_previous = fft_magnitude.copy() 626 | feature_vector = np.zeros((n_total_feats, 1)) 627 | 628 | # zero crossing rate 629 | feature_vector[0] = zero_crossing_rate(x) 630 | 631 | # short-term energy 632 | feature_vector[1] = energy(x) 633 | 634 | # short-term entropy of energy 635 | feature_vector[2] = energy_entropy(x) 636 | 637 | # sp centroid/spread 638 | [feature_vector[3], feature_vector[4]] = \ 639 | spectral_centroid_spread(fft_magnitude, 640 | sampling_rate) 641 | 642 | # spectral entropy 643 | feature_vector[5] = \ 644 | spectral_entropy(fft_magnitude) 645 | 646 | # spectral flux 647 | feature_vector[6] = \ 648 | spectral_flux(fft_magnitude, 649 | fft_magnitude_previous) 650 | 651 | # spectral rolloff 652 | feature_vector[7] = \ 653 | spectral_rolloff(fft_magnitude, 0.90) 654 | 655 | # MFCCs 656 | mffc_feats_end = n_time_spectral_feats + n_mfcc_feats 657 | feature_vector[n_time_spectral_feats:mffc_feats_end, 0] = \ 658 | mfcc(fft_magnitude, fbank, n_mfcc_feats).copy() 659 | 660 | # chroma features 661 | chroma_names, chroma_feature_matrix = \ 662 | chroma_features(fft_magnitude, sampling_rate, num_fft) 663 | chroma_features_end = n_time_spectral_feats + n_mfcc_feats + \ 664 | n_chroma_feats - 1 665 | feature_vector[mffc_feats_end:chroma_features_end] = \ 666 | chroma_feature_matrix 667 | feature_vector[chroma_features_end] = chroma_feature_matrix.std() 668 | if not deltas: 669 | features.append(feature_vector) 670 | else: 671 | # delta features 672 | if count_fr > 1: 673 | delta = feature_vector - feature_vector_prev 674 | feature_vector_2 = np.concatenate((feature_vector, delta)) 675 | else: 676 | feature_vector_2 = np.concatenate((feature_vector, 677 | np.zeros(feature_vector. 678 | shape))) 679 | feature_vector_prev = feature_vector 680 | features.append(feature_vector_2) 681 | 682 | fft_magnitude_previous = fft_magnitude.copy() 683 | 684 | features = np.concatenate(features, 1) 685 | return features, feature_names 686 | -------------------------------------------------------------------------------- /pyAudioAnalysis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyiannak/pyAudioAnalysis/a246ebf4c553db49ed4400e3a902d39c89ec0043/pyAudioAnalysis/__init__.py -------------------------------------------------------------------------------- /pyAudioAnalysis/audacityAnnotation2WAVs.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import os 3 | import audioBasicIO 4 | import sys 5 | import csv 6 | import scipy.io.wavfile as wavfile 7 | 8 | 9 | def annotation2files(wavFile, csvFile): 10 | """ 11 | Break an audio stream to segments of interest, 12 | defined by a csv file 13 | 14 | - wavFile: path to input wavfile 15 | - csvFile: path to csvFile of segment limits 16 | 17 | Input CSV file must be of the format \t\t