{"id":3190,"date":"2017-11-20T00:00:43","date_gmt":"2017-11-20T08:00:43","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3190"},"modified":"2018-01-09T06:46:45","modified_gmt":"2018-01-09T14:46:45","slug":"sonic-data-analysis-with-sox","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3190","title":{"rendered":"Sonic data analysis with SoX"},"content":{"rendered":"<p>In this post I&#8217;ll be using SoX to export audio to data values that can be processed outside the audio realm. The example I&#8217;ll use here is a breif recording that will be plotted with GNUPlot. SoX and other programs provide spectrograms, which are frequency domain images of audio files. I&#8217;ll be using GNUPlot to create an image of an audio file in the time domain.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/11\/44k_Mono.wav.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3191\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/11\/44k_Mono.wav.png\" alt=\"\" width=\"640\" height=\"442\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono.wav.png 640w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono.wav-300x207.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono.wav-391x270.png 391w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>First, I&#8217;ll use this command to convert the audio wav file into a text based dat file.<\/p>\n<pre>sox \"\/home\/local\/Desktop\/Export to Data\/44k_Mono.wav\" \"\/home\/local\/Desktop\/Export to Data\/44k_Mono.dat\"\r\n<\/pre>\n<p>Here is a sample of first few lines of the resulting dat file.<\/p>\n<pre>; Sample Rate 44100\r\n; Channels 1\r\n0 0\r\n2.2675737e-05 0\r\n4.5351474e-05 -3.0517578e-05\r\n6.8027211e-05 0\r\n9.0702948e-05 0\r\n0.00011337868 0\r\n<\/pre>\n<p>The first two lines contain the sample rate and number of channels in the audio. The remaining lines contain two columns of data, the first is timestamp and the next is the audio level at that point in time. The example above uses 44100 samples per second, so each row increments in time by 22.6 microseconds.<\/p>\n<p>For our purposes, we are only interested in the second row. So we&#8217;ll need to remove the first 2 rows and the first column from the dat file.<\/p>\n<p>Now open up GNUPlot by entering &#8220;gnuplot&#8221; at the terminal. From here enter in the following command to create a simple plot with the resulting audio data.<\/p>\n<pre>set output \"\/home\/local\/Desktop\/Export to Data\/44k_Mono.png\"\r\nset terminal pngcairo background rgb 'black'\r\nset xlabel 'Time' tc rgb 'white'\r\nset ylabel 'Amplitude' tc rgb 'white'\r\nplot \"\/home\/local\/Desktop\/Export to Data\/44k_Mono.txt\" with lines linecolor rgb \"green\"\r\n<\/pre>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/11\/44k_Mono.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3192\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/11\/44k_Mono.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono.png 640w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono-300x225.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/11\/44k_Mono-360x270.png 360w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>SoX provides a way to export audio into numeric data. This is a fairly advanced feature that allows analysis of data well beyond the audio realm. Sonic locating and triangulation are some possible uses, but these applications require a high degree of time domain accuracy.\u00a0 Even so, the information gathered from a simple microphone can be used for data logging.\u00a0 Having the audio data available is the key.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll be using SoX to export audio to data values that can be processed outside the audio realm. The example I&#8217;ll use here is a breif recording that will be plotted with GNUPlot. SoX and other programs provide spectrograms, which are frequency domain images of audio files. I&#8217;ll be using GNUPlot to create an image of an audio file in the time domain. First, I&#8217;ll use this command to convert the audio wav file into a text&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3190\"> 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":[3],"tags":[],"class_list":["post-3190","post","type-post","status-publish","format-standard","hentry","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3190","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=3190"}],"version-history":[{"count":3,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3190\/revisions"}],"predecessor-version":[{"id":3194,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3190\/revisions\/3194"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}