not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.9 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>meSpeak Flash Fallback</title>
  6. <link href="http://fonts.googleapis.com/css?family=Open+Sans&amp;subset=latin" rel="stylesheet" type="text/css" />
  7. <link href="http://fonts.googleapis.com/css?family=Lato:300&amp;subset=latin" rel="stylesheet" type="text/css" />
  8. <script type="text/javascript" src="../mespeak.js"></script>
  9. <script type="text/javascript" src="flashFallback.js"></script>
  10. <script type="text/javascript">
  11. meSpeak.loadConfig("../mespeak_config.json");
  12. meSpeak.loadVoice("../voices/en/en.json");
  13. var fallbackInstalled = false;
  14. var hasTypedArrays = Boolean(window.Int32Array && window.Float32Array
  15. && (window.Int32Array.prototype.subarray || window.Int32Array.subarray)
  16. ),
  17. canSpeak = (hasTypedArrays && window.meSpeak && meSpeak.canPlay());
  18. function checkAndInstall() {
  19. // check typed array support (we need this) and wav-support (we fallback, if not present)
  20. if (hasTypedArrays && window.meSpeak && !meSpeak.canPlay()) {
  21. canSpeak = installFallback();
  22. }
  23. }
  24. function installFallback() {
  25. // install with explicit default values
  26. // swf will be 2px x 2px (h x w), transparent
  27. return fallbackInstalled = meSpeakFlashFallback.install(
  28. 'meSpeakFallback.swf', // url
  29. 'meSpeakFallback', // id of swf object
  30. null // parent element to inject into
  31. // (default: append to body)
  32. );
  33. }
  34. function fallbackSpeak() {
  35. meSpeakFlashFallback.speak('Hello world.', { 'speed': 180 } );
  36. }
  37. // some functions for abstracting
  38. function speakAny( txt, options, vol ) {
  39. if (fallbackInstalled) {
  40. meSpeakFlashFallback.speak( txt, options );
  41. }
  42. else if (canSpeak) {
  43. meSpeak.speak( txt, options, vol );
  44. }
  45. }
  46. function setVolume( vol) {
  47. if (fallbackInstalled) {
  48. meSpeakFlashFallback.setVolume( vol );
  49. }
  50. else if (canSpeak) {
  51. meSpeak.setVolume( vol );
  52. }
  53. }
  54. function fallbackReady() {
  55. // check if the swf has loaded and performed a handshake, indicating that it's available
  56. return meSpeakFlashFallback.ready();
  57. }
  58. // install only, if needed
  59. // if (document.addEventListener) document.addEventListener('DOMContentLoaded', checkAndInstall, false);
  60. // install unconditionally (for testing purpose)
  61. if (document.addEventListener) document.addEventListener('DOMContentLoaded', installFallback, false);
  62. </script>
  63. <style type="text/css">
  64. html
  65. {
  66. margin: 0;
  67. padding: 2em 1.5em 4.5em 1.5em;
  68. background-color: #e2e3e4;
  69. }
  70. body
  71. {
  72. max-width: 900px;
  73. padding: 2px 40px 60px 40px;
  74. margin: 0 auto 0 auto;
  75. background-color: #fafafb;
  76. color: #111;
  77. font-family: 'Open Sans',sans-serif;
  78. font-size: 13px;
  79. line-height: 19px;
  80. }
  81. h1,h2,h3,h4
  82. {
  83. font-family: 'Lato',sans-serif;
  84. font-weight: 300;
  85. }
  86. h1 {
  87. font-size: 46px;
  88. line-height: 46px;
  89. color: #2681a7;
  90. margin-top: 0.5em;
  91. margin-bottom: 0.5em;
  92. padding: 0;
  93. }
  94. h2
  95. {
  96. font-size: 36px;
  97. color: #111;
  98. margin-top: 0;
  99. margin-bottom: 1.5em;
  100. clear: both;
  101. }
  102. h1 span.pict { font-size: 38px; color: #ccc; margin-left: 0.5em; letter-spacing: -2px; }
  103. p.codesample,xmp
  104. {
  105. margin: 1em 0;
  106. padding: 1em 0 1em 2em;
  107. white-space: pre;
  108. font-family: monospace;
  109. line-height: 18px;
  110. background-color: #f2f3f5;
  111. color: #111;
  112. }
  113. a { color: #006f9e; }
  114. a:hover,a:focus { color: #2681a7; }
  115. a:active { color: #cd360e; }
  116. </style>
  117. </head>
  118. <body>
  119. <h1>meSpeak.js <span class="pict">(( &bull; ))</span></h1>
  120. <h2>Flash Fallback <small>(for IE 10)</small></h2>
  121. <p>A fallback to play meSpeak's wav-files via Flash.<br />Since typed arrays are still a requirement, the only use-case is MS Internet Explorer 10.<br />
  122. Please note that, since we may not send binary data to a swf-object, the data has to be copied internally to a binary object, which may take some time and memory.<br />Because of this, the status of this solution is at best &quot;experimental&quot; and not for everyday use.</p>
  123. <p>The fallback &quot;meSpeakFallback.swf&quot; uses the <a href="http://code.google.com/p/as3wavsound/">AS3WavSound</a> library (v0.9) for wav-playback inside the SWF. (Ironically Flash doesn't support native wav-playback either.)<br />The swf-file is compiled for network use, meaning it will work only, if loaded over a network (web-server).</p>
  124. <p>For testing, the fallback is installed for all browsers on this page:
  125. <input type="button" value="speak: Hello world." onclick="fallbackSpeak();" /></p>
  126. <p>See page source for API &amp; details.</p>
  127. <p>Download: <a href="http://www.masswerk.at/mespeak/msie_flashFallback.zip">msie_flashFallback.zip</a><br />
  128. <em>(Installation: Put the unzipped directory inside your mespeak-directory.)</em></p>
  129. <hr style="margin-top: 2em; margin-bottom: 2em;">
  130. <p><strong>A Note on Usage:</strong><br />While the fallback-script strips down the coded needed to inject a swf-object to a minimum, best practice would be to include the script only, if applicable (i.e.: for MS IE 10 only), using MS-specific conditional comments:</p>
  131. <xmp style="margin-left: 1em;">
  132. <!--[if IE 10]>
  133. <script type="text/javascript" src="flashFallback.js"></script>
  134. <![endif]-->
  135. </xmp>
  136. <p>If doing so, you would have to check for the existence of <code>meSpeakFlashFallback</code> first, before calling it:</p>
  137. <xmp style="margin-left: 1em;">
  138. if (window.meSpeakFlashFallback) callbackInstalled = meSpeakFlashFallback.install();
  139. // later, see page source for API details and usage
  140. if (callbackInstalled) meSpeakFlashFallback.speak('Hello world.');
  141. </xmp>
  142. <p>This way, page- and memory-loads are reduced to a minimum for all browsers.</p>
  143. <p>Please note that there is a delay between calling <code>install()</code> and the fallback actually being available, since the swf-file has to load and initialize first.</p>
  144. <p>&nbsp;</p>
  145. <p>Norbert Landsteiner, mass:werk &ndash; media environments, <a href="http://www.masswerk.at/" target="_top">www.masswerk.at</a><br />
  146. Vienna, July 2013</p>
  147. </body>
  148. </html>