{"id":3153,"date":"2017-10-23T00:00:37","date_gmt":"2017-10-23T07:00:37","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3153"},"modified":"2018-01-09T06:46:46","modified_gmt":"2018-01-09T14:46:46","slug":"noise-filtering-with-sox","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3153","title":{"rendered":"Noise Filtering with SoX"},"content":{"rendered":"<p>In this post I&#8217;ll cover how to remove noise in an audio file using SoX. I&#8217;ll be using a Raspberry Pi which does not have an audio input by default. To get audio, I used an simple USB audio microphone to capture audio. The OS I&#8217;m running on my Pi is Ubuntu Mate and there was no need for anything to get the microphone to run.<\/p>\n<p>Once it was plugged in, I ran this command to view the properties of it. The information will be needed later when capturing audio with FFMpeg.<\/p>\n<pre>arecord -l\r\ncard 0: Device [USB PnP Sound Device], device 1: USB Audio [USB Audio]\r\nSubdevices: 1\/1\r\nSubdevice #0: subdevice #0<\/pre>\n<p>I then used this command to capture the audio on the Raspberry Pi.<\/p>\n<pre>ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0,1 -t 60 Audio_Pi.wav\r\n### Here is a breakdown of the FFMpeg command.\r\n# -f alsa = Input format is direct from ALSA\r\n# -ac 1 = Audio Channel 1 (Mono)\r\n# -ar 44100 = Audio Sampling Rate of 44100 bits per second\r\n# -i hw:0,1 = ALSA input device hardware, Card 0, Device 1, see arecord -l results above\r\n# -t 60 = Capture for a time duration of 60 seconds\r\n# Audio_Pi.wav = The saved file that the audio data will be stored to<\/pre>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-audio.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3157\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-audio.png\" alt=\"\" width=\"640\" height=\"442\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-audio.png 640w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-audio-300x207.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-audio-391x270.png 391w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Something stood out when I did a spectrogram, all of the harmonic distortion. There was also a background noise across the entire spectrum. I wasn&#8217;t sure the source of the noise so I did a silenced microphone recording. Basically this was placing electric tape on the microphone opening and installing the microphone on a USB extension cable. Then I wrapped the microphone in a towel. The results still showed the hiss and harmonic distortion. Here are the commands I used to capture then cut a segment that would become the foundation of the noise profile.<\/p>\n<pre>ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0,1 -t 60 Audio_Pi_SilencedMic.wav\r\nffmpeg -i \"Audio_Pi_SilencedMic.wav\" -ss 00:00:10 -t 00:00:10 -acodec copy \"Audio_Pi_SilencedMicSegment.wav\"<\/pre>\n<p>The noise profile is created with SoX. It is a reference when applying the noise filter on an audio file. Here is the command to create the noise profile.<\/p>\n<pre>sox \"Audio_Pi_SilencedMicSegment.wav\" -n noiseprof \"Audio_Pi_SilencedMicSegment.prof\"<\/pre>\n<p>Now with the noise profile created, I then applied the SoX noise filtering command.<\/p>\n<pre>sox \"Audio_Pi.wav\" \"Audio_Pi_NoNoise.wav\" noisered \"Audio_Pi_SilencedMicSegment.prof\" 0.016<\/pre>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-filter.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3158\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-filter.png\" alt=\"\" width=\"640\" height=\"442\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-filter.png 640w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-filter-300x207.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/10\/Picture-of-resulting-filter-391x270.png 391w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>The results were impressive. But after some amplification of the results, I began to notice artifacts introduced into the audio. Still, to create simple noise filtering with command line tools on the Raspberry Pi, SoX does a decent job.<\/p>\n<p>Thanks goes out to Andrew Zhang for his post, <a href=\"http:\/\/goodagood.blogspot.com\/2017\/01\/audio-recording-from-usb-microphone.html\">http:\/\/goodagood.blogspot.com\/2017\/01\/audio-recording-from-usb-microphone.html<\/a>. There are several posts covering noise filtering with SoX, far too many for me to give credit here, thank you. I hope you have enjoyed this and I look forward to having you back again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll cover how to remove noise in an audio file using SoX. I&#8217;ll be using a Raspberry Pi which does not have an audio input by default. To get audio, I used an simple USB audio microphone to capture audio. The OS I&#8217;m running on my Pi is Ubuntu Mate and there was no need for anything to get the microphone to run. Once it was plugged in, I ran this command to view the properties of&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3153\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[],"class_list":["post-3153","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3153"}],"version-history":[{"count":6,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3153\/revisions"}],"predecessor-version":[{"id":3161,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3153\/revisions\/3161"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}