{"id":5376,"date":"2017-04-29T02:20:54","date_gmt":"2017-04-29T02:20:54","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5376"},"modified":"2017-04-29T02:20:54","modified_gmt":"2017-04-29T02:20:54","slug":"apply-fft-list-wav-files-python","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/apply-fft-list-wav-files-python\/","title":{"rendered":"Apply FFT to a list of wav files with Python"},"content":{"rendered":"<pre lang=\"python\">\nimport pickle\nimport pandas\n\nfrom os import listdir\nfrom os.path import isfile, join\nimport os\n\nimport scipy.io.wavfile as wavfile\nimport scipy\nimport scipy.fftpack\n\nimport numpy as np\n\ndef process(fileWav):\n  signal = wavfile.read(fileWav)[1]\n\n  t = scipy.linspace(0,120,4000)\n\n  FFT = abs(scipy.fft(signal))\n  freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])\n\n  return np.array(freqs)\n\ndef all_files(mypath):\n  return [f for f in listdir(mypath) if isfile(join(mypath, f))]\n\ndef get_and_save_data(path, file): \n  print(\"Processing... \" + file)\n  data = [process(path + \"\\\\\" + file)]\n  towrite = \"ffts\\\\\" + file + \".pickled\"\n  print(towrite)\n\n  pickle.dump(data, open(towrite, \"wb\"))\n\ndef process_all_files(path):\n  print(\"Loading directory \" + path) \n  found = [file for file in all_files(path)]\n\n  random.shuffle(found)\n\n  for file in found:\n    if not isfile(\"ffts\\\\\" + file + \".pickled\"):\n      print(\"Starting a thread for \" + file)\n      get_and_save_data(path, file)\n\nprocess_all_files(\"samples\")\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Code to run a folder through FFT algorithm and save in Python<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[228,395,447,584],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5376"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5376"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5376\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}