{"id":8520,"date":"2017-04-28T09:00:38","date_gmt":"2017-04-28T13:00:38","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=8520"},"modified":"2018-06-21T09:36:05","modified_gmt":"2018-06-21T13:36:05","slug":"the-speech-transmission-index-sti","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2017\/04\/28\/the-speech-transmission-index-sti\/","title":{"rendered":"The Speech Transmission Index (STI)"},"content":{"rendered":"<p><div class=\"alert alert-info\"> <span class=\"alert_icon icon-alert-info-reverse\"><\/span><p class=\"alert_heading\"><strong>Note<\/strong><\/p><p>The file submission referenced in this post is no longer available on File Exchange.<\/p><\/div> <\/p>\n<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n <introduction><\/p>\n<p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is The Speech Transmission Index (STI) by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/6238671\">Jacob D<\/a>.\n      <\/p>\n<p>   <\/introduction><\/p>\n<h3>Background<a name=\"1\"><\/a><\/h3>\n<p>According to Wikipedia, the Speech Transmission Index is a metric ranging from 0 to 1 that can be used to understand how intelligible speech will be across a room.  Jacob has provided us a with a tool to do this.\n   <\/p>\n<p>I wanted to test it with the three microphones I have on my desk:<\/p>\n<div>\n<ul>\n<li>Laptop microphone (low quality)<\/li>\n<li>Headset (high quality, used for recording webinars)<\/li>\n<li>Speaker (decent quality)<\/li>\n<\/ul><\/div>\n<p>To use this, I needed to generate an impulse response and record it on the three devices.  This was surprisingly simple with<br \/>\n      <a href=\"https:\/\/www.mathworks.com\/products\/simulink.html\">Simulink<\/a> and the <a href=\"https:\/\/www.mathworks.com\/products\/audio-system.html\">Audio System Toolbox<\/a>.  I created a simple Simulink model and used three <a href=\"https:\/\/www.mathworks.com\/help\/audio\/ref\/audiodevicereader.html\">Audio Device Reader Blocks<\/a> to read from the three mics, each linked to its own WAV file writer.\n   <\/p>\n<p>Here&#8217;s the Simulink model and the audio signal displayed with a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/dashboardscope.html\">dashboard scope<\/a>.\n   <\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainsti\/simulinkmodel.png\"> <\/p>\n<p>Then, being sophisticated, I took a ChannelLock wrench and used it to hit a book on my desk next to the microphones to generate the impulse response.  Don&#8217;t worry, the book was one of those unexciting ones you get from corporate training sessions, not something technical.\n   <\/p>\n<p>With the audio files stored, I can then read each one in and calculate its STI.  To simplify this, I&#8217;m used some of the <a href=\"https:\/\/www.mathworks.com\/solutions\/big-data-matlab.html\">&#8220;Big Data&#8221;<\/a> tools which provide an easy interface for working with many files even if the data aren&#8217;t large.  Here I will use a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/filedatastore.html\"><tt>fileDatastore<\/tt><\/a> with a custom read function which reads the file, calculates its STI, and plots the original signal.  Notice that I do not need to handle the looping over the files and other bookkeeping things myself.\n   <\/p>\n<p>Here&#8217;s the custom read function, <i>calcSTI<\/i>:\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">\r\n<span style=\"color: #0000FF\">function<\/span> thisSTI = calcSTI(filename)\r\n<span style=\"color: #228B22\">% Gets STI given audio filename    <\/span>\r\n    info = audioinfo(filename);\r\n    fs = info.SampleRate;\r\n    data = audioread(filename);\r\n    thisSTI = STI(data, fs);\r\n    hold <span style=\"color: #A020F0\">on<\/span>\r\n    plot(data, <span style=\"color: #A020F0\">'DisplayName'<\/span>, filename)\r\n<span style=\"color: #0000FF\">end<\/span>\r\n<\/pre>\n<p>Use it to read all files and display results:<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">ds = fileDatastore(<span style=\"color: #A020F0\">'*.wav'<\/span>, <span style=\"color: #A020F0\">'ReadFcn'<\/span>, @calcSTI)\r\nstis = readall(ds);\r\nleg = legend(<span style=\"color: #A020F0\">'show'<\/span>);\r\nleg.Interpreter = <span style=\"color: #A020F0\">'none'<\/span>;\r\nleg.Location = <span style=\"color: #A020F0\">'southoutside'<\/span>;\r\nylabel(<span style=\"color: #A020F0\">'Audio Signal'<\/span>)\r\nxlabel(<span style=\"color: #A020F0\">'Samples'<\/span>)\r\nSTIs = table(ds.Files, stis, <span style=\"color: #A020F0\">'VariableNames'<\/span>, {<span style=\"color: #A020F0\">'Filename'<\/span>, <span style=\"color: #A020F0\">'STI'<\/span>})<\/pre>\n<pre style=\"font-style:oblique\">ds = \r\n  FileDatastore with properties:\r\n\r\n      Files: {\r\n             'C:\\Documents\\MATLAB\\potw\\STI\\outputhandset.wav';\r\n             'C:\\Documents\\MATLAB\\potw\\STI\\outputheadset.wav';\r\n             'C:\\Documents\\MATLAB\\potw\\STI\\outputlaptop.wav'\r\n             }\r\n    ReadFcn: @calcSTI\r\nSTIs =\r\n  3&times;2 table\r\n                        Filename                          STI   \r\n    ________________________________________________    ________\r\n    'C:\\Documents\\MATLAB\\potw\\STI\\outputhandset.wav'    [0.8083]\r\n    'C:\\Documents\\MATLAB\\potw\\STI\\outputheadset.wav'    [0.9348]\r\n    'C:\\Documents\\MATLAB\\potw\\STI\\outputlaptop.wav'     [0.7363]\r\n<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainsti\/mainsti_01.png\"> <\/p>\n<p>The STIs look about like what I would expect with the headset being the best, the speaker phone in the middle, and the laptop the lowest.\n   <\/p>\n<h3>Comments<a name=\"3\"><\/a><\/h3>\n<p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=8520#respond\">here<\/a>.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_3377255117ca4cc2830074ba4434b3f4() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='3377255117ca4cc2830074ba4434b3f4 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3377255117ca4cc2830074ba4434b3f4';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sean de Wolski';\n        copyright = 'Copyright 2017 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_3377255117ca4cc2830074ba4434b3f4()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n            the MATLAB code<br \/>\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2017a<\/p>\n<\/div>\n<p><!--\n3377255117ca4cc2830074ba4434b3f4 ##### SOURCE BEGIN #####\n%% The Speech Transmission Index (STI)\n%\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/62512 The Speech Transmission Index (STI)> by\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/6238671 Jacob D>.\n% \n\n%% Background\n%\n% According to Wikipedia, the Speech Transmission Index is a metric ranging\n% from 0 to 1 that can be used to understand how intelligible speech will\n% be across a room.  Jacob has provided us a with a tool to do this.\n%\n% I wanted to test it with the three microphones I have on my desk:\n% \n% * Laptop microphone (low quality)\n% * Headset (high quality, used for recording webinars)\n% * Speaker (decent quality)\n%\n% To use this, I needed to generate an impulse response and record it on\n% the three devices.  This was surprisingly simple with\n% <https:\/\/www.mathworks.com\/products\/simulink.html Simulink> and the\n% <https:\/\/www.mathworks.com\/products\/audio-system.html Audio System\n% Toolbox>.  I created a simple Simulink model and used three\n% <https:\/\/www.mathworks.com\/help\/audio\/ref\/audiodevicereader.html Audio\n% Device Reader Blocks> to read from the three mics, each linked to its own\n% WAV file writer.\n%\n% Here's the Simulink model and the audio signal displayed with a\n% <https:\/\/www.mathworks.com\/help\/simulink\/slref\/dashboardscope.html\n% dashboard scope>.\n%\n% <<simulinkmodel.png>>\n%\n% Then, being sophisticated, I took a ChannelLock wrench and used it to hit\n% a book on my desk next to the microphones to generate the impulse\n% response.  Don't worry, the book was one of those unexciting ones you get\n% from corporate training sessions, not something technical.\n%\n% With the audio files stored, I can then read each one in and calculate its\n% STI.  To simplify this, I'm used some of the\n% <https:\/\/www.mathworks.com\/solutions\/big-data-matlab.html \"Big Data\">\n% tools which provide an easy interface for working with many files even if\n% the data aren't large.  Here I will use a\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/filedatastore.html\n% |fileDatastore|> with a custom read function which reads the file,\n% calculates its STI, and plots the original signal.  Notice that I do not\n% need to handle the looping over the files and other bookkeeping things\n% myself.\n% \n% Here's the custom read function, _calcSTI_:\n%\n% <include>calcSTI.m<\/include>\n%\n% Use it to read all files and display results:\nds = fileDatastore('*.wav', 'ReadFcn', @calcSTI)\nstis = readall(ds);\nleg = legend('show');\nleg.Interpreter = 'none';\nleg.Location = 'southoutside';\nylabel('Audio Signal')\nxlabel('Samples')\nSTIs = table(ds.Files, stis, 'VariableNames', {'Filename', 'STI'})\n\n\n%%\n%\n% The STIs look about like what I would expect with the headset being the\n% best, the speaker phone in the middle, and the laptop the lowest.\n\n%% Comments\n% \n% Give it a try and let us know what you think\n% <https:\/\/blogs.mathworks.com\/pick\/?p=8520#respond here>.\n \n\n##### SOURCE END ##### 3377255117ca4cc2830074ba4434b3f4\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainsti\/simulinkmodel.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p> NoteThe file submission referenced in this post is no longer available on File Exchange. <\/p>\n<p>Sean&#8216;s pick this week is The Speech Transmission Index (STI) by Jacob D.<\/p>\n<p>  &#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2017\/04\/28\/the-speech-transmission-index-sti\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8520"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=8520"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8520\/revisions"}],"predecessor-version":[{"id":9894,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8520\/revisions\/9894"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=8520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=8520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=8520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}