title: Text to speech of highlighted text
body: <p>for a questionnaire which is partly for people who can't read, I would need a text to speech application. For reasons of usability, the text should be read when highlighted ("marked").
  While researching different ways on how to do this, I found the following tool, which should exactly do that. For some reasons it won't work.
  I want to use it on the questionnaire software SoSci, so that might be an issue (does anybody have any experience there?). </p>
  
  <p>I would appreciate  any hint, what I am missing, but also other approaches on how to solve the problem are more than welcome! </p>
  
  <p>Best wishes</p>
  
  <pre><code>&lt;script&gt;        
  function getSelectionText() {
          var text = "";
          if (window.getSelection) {
              text = window.getSelection().toString();
          // for Internet Explorer 8 and below. For Blogger, you should use &amp;amp;&amp;amp; instead of &amp;&amp;.
          } else if (document.selection &amp;&amp; document.selection.type != "Control") { 
              text = document.selection.createRange().text;
          }
          return text;
      }
      $(document).ready(function (){ // when the document has completed loading
         $(document).mouseup(function (e){ // attach the mouseup event for all div and pre tags
            setTimeout(function() { // When clicking on a highlighted area, the value stays highlighted until after the mouseup event, and would therefore stil be captured by getSelection. This micro-timeout solves the issue. 
               responsiveVoice.cancel(); // stop anything currently being spoken
               responsiveVoice.speak(getSelectionText()); //speak the text as returned by getSelectionText
            }, 1);
         });
      });
      &lt;/script&gt;
  </code></pre>