~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to demos/espeak/espeak.html

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<title>Text-to-Speech on the Web</title>
 
3
<head>
 
4
  <script>
 
5
    // This demo is licensed under the GNU GPL.
 
6
 
 
7
    var print = console.log;
 
8
 
 
9
    var Module = {
 
10
      arguments: ['-w', 'wav.wav', '-v', 'en/en-us', '--path=/espeak'],
 
11
      noInitialRun: true
 
12
    };
 
13
  </script>
 
14
  <script src="espeak.js"></script>
 
15
  <script>
 
16
    // expects the webserver to run in the parent of espeak-data/
 
17
 
 
18
    FS.createPath('/', 'espeak/espeak-data', true, false);
 
19
    ['phontab', 'phonindex', 'phondata', 'intonations', 'en_dict'].forEach(function(datafile) {
 
20
      FS.createLazyFile('/espeak/espeak-data', datafile, 'espeak-data/' + datafile, true, false);
 
21
    });
 
22
 
 
23
    FS.createPath('/', 'espeak/espeak-data/voices/en', true, false);
 
24
    FS.createLazyFile('/espeak/espeak-data/voices/en', 'en-us', 'espeak-data/voices/en/en-us', true, false);
 
25
 
 
26
    FS.root.write = true;
 
27
 
 
28
    function talk(text) {
 
29
      Module.arguments.push(text);
 
30
      run();
 
31
      Module.arguments.pop();
 
32
 
 
33
      var wav = FS.root.contents['wav.wav'].contents;
 
34
 
 
35
      function encode64(data) {
 
36
        var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
 
37
        var PAD = '=';
 
38
        var ret = '';
 
39
        var leftchar = 0;
 
40
        var leftbits = 0;
 
41
        for (var i = 0; i < data.length; i++) {
 
42
          leftchar = (leftchar << 8) | data[i];
 
43
          leftbits += 8;
 
44
          while (leftbits >= 6) {
 
45
            var curr = (leftchar >> (leftbits-6)) & 0x3f;
 
46
            leftbits -= 6;
 
47
            ret += BASE[curr];
 
48
          }
 
49
        }
 
50
        if (leftbits == 2) {
 
51
          ret += BASE[(leftchar&3) << 4];
 
52
          ret += PAD + PAD;
 
53
        } else if (leftbits == 4) {
 
54
          ret += BASE[(leftchar&0xf) << 2];
 
55
          ret += PAD;
 
56
        }
 
57
        return ret;
 
58
      }
 
59
 
 
60
      for (var i = 0; i < wav.length; i++)
 
61
        wav[i] = unSign(wav[i], 8);
 
62
 
 
63
      document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
 
64
      document.getElementById("player").play();
 
65
    }
 
66
  </script>
 
67
</head>
 
68
<body>
 
69
  <h1>Text-To-Speech on the Web</h1>
 
70
  <form onsubmit="talk(text.value); return false">
 
71
    Text: <input type="text" name="text" size=50 value="Never gonna give, you, up."><input type="submit" value="Go!">
 
72
  </form>
 
73
  <hr>
 
74
  <p>
 
75
    This demo is 100% clientside JavaScript. It uses <a href="http://espeak.sourceforge.net/">eSpeak</a>, an open source
 
76
    speech synthesizer, which was compiled from C++ to JavaScript using <a href="http://emscripten.org">Emscripten</a>.
 
77
    Source code for this demo can be found <a href="espeak_src.tar.bz2">here</a>.
 
78
  </p>
 
79
  <p>
 
80
    Browser requirements:
 
81
    <ul>
 
82
      <li><b>Typed arrays</b>. The eSpeak code is not portable to the extent that would be necessary to avoid using typed arrays.
 
83
          (It should however be possible to rewrite small bits of eSpeak to fix that.)
 
84
          This is present in Firefox and Chrome, but not IE, Safari or Opera.</li>
 
85
      <li><b>Support for WAV audio in data URIs</b>. eSpeak's simplest form of output is a WAV file, and the easiest way to use
 
86
          that is via a data URI. (It should however be possible to extract the raw audio directly by hacking eSpeak.)
 
87
          This is present in Firefox, Safari and Opera, but not IE or Chrome.</li>
 
88
    </ul>
 
89
    So currently this demo will only work in Firefox. Help is welcome regarding the workarounds mentioned above
 
90
    that will let it work elsewhere, we would like to develop this demo into a useful project for people to use around the web.
 
91
  </p>
 
92
  <div id="audio"></div>
 
93
</body>
 
94
</html>
 
95