{"cells":[{"metadata":{},"cell_type":"markdown","source":"**Do not forget** \nyou can resample audio file to 8K or 16K rates. Also you need to convert audio samples into wav format.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"![](https://i.stack.imgur.com/ptACM.png)","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"You could do it by hand if you understand the principle, but I strongly recommend you to use a library. The reason is that interpolating the right way isn't easy or either obvious.\n\nYou could use a linear interpolation (connect points with a line) or a binomial interpolation (connect three points with a piece of polynom) or (sometimes the best for sound) use a Fourier transform and interpolate in the space of frequency. Since fourier transform isn't something you want to re-write by hand, if you want a good subsampling/supsampling, See the following picture for two curves of upsampling using a different algorithm from scipy. The \"resampling\" function use fourier","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"![](https://i.stack.imgur.com/93KOf.png)","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"**Manipulate audio with a simple and easy high level interface To convert mp3 to wav**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install pydub","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"collapsed":true},"cell_type":"code","source":"import os\n\nfrom os import path\nfrom pydub import AudioSegment\n\n\n \n\ntest_set=\"./test_set/\"\n \n\nos.mkdir(test_set) \n \n\nfor dirname, _, filenames in os.walk('../input/quran-asr-challenge/test_set'):\n    for filename in filenames:\n        # files                                                                         \n        src = \"../input/quran-asr-challenge/test_set/\"+filename\n        dst = test_set+os.path.splitext(filename)[0]+\".wav\"\n        # convert wav to mp3                                                            \n        sound = AudioSegment.from_mp3(src)\n        sound = sound.set_frame_rate(8000)\n        sound.export(dst, format=\"wav\")\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**References**","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"https://github.com/jiaaro/pydub\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"https://pydub.com/","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"https://stackoverflow.com/questions/30619740/downsampling-wav-audio-file","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# **Thankyou For Reading**","execution_count":null}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}