Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor speak.js into speakClient.js and speakGenerator.js
  • Loading branch information
kripken committed Jan 13, 2012
1 parent 29aff21 commit f62f0be
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 41 deletions.
3 changes: 2 additions & 1 deletion demo.html
Expand Up @@ -4,7 +4,8 @@
<script>
// This demo is licensed under the GNU GPL.
</script>
<script src="speak.js"></script>
<script src="speakGenerator.js"></script>
<script src="speakClient.js"></script>
</head>
<body>
<h1>speak.js</h1>
Expand Down
3 changes: 2 additions & 1 deletion helloworld.html
@@ -1,6 +1,7 @@
<html>
<head>
<script src="speak.js"></script>
<script src="speakGenerator.js"></script>
<script src="speakClient.js"></script>
</head>
<body>
<button onclick="speak('hello world')">Talk</button>
Expand Down
1 change: 0 additions & 1 deletion speak.js

This file was deleted.

32 changes: 32 additions & 0 deletions speakClient.js
@@ -0,0 +1,32 @@
function speak(text, args) {
function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {
var curr = (leftchar >> (leftbits-6)) & 0x3f;
leftbits -= 6;
ret += BASE[curr];
}
}
if (leftbits == 2) {
ret += BASE[(leftchar&3) << 4];
ret += PAD + PAD;
} else if (leftbits == 4) {
ret += BASE[(leftchar&0xf) << 2];
ret += PAD;
}
return ret;
}

var wav = generateSpeech(text, args);

document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
document.getElementById("player").play();
}

6 changes: 3 additions & 3 deletions src/emscripten.sh
Expand Up @@ -20,9 +20,9 @@ echo "dis"

echo "emscripten"
$EMSCRIPTEN/emcc -O2 --js-transform "python bundle.py" speak.ll -o speak.raw.js
cat shell_pre.js > ../speak.js
cat speak.raw.js >> ../speak.js
cat shell_post.js >> ../speak.js
cat shell_pre.js > ../speakGenerator.js
cat speak.raw.js >> ../speakGenerator.js
cat shell_post.js >> ../speakGenerator.js



Expand Down
34 changes: 1 addition & 33 deletions src/post.js
Expand Up @@ -34,37 +34,5 @@

run();

var wav = FS.root.contents['wav.wav'].contents;

function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {
var curr = (leftchar >> (leftbits-6)) & 0x3f;
leftbits -= 6;
ret += BASE[curr];
}
}
if (leftbits == 2) {
ret += BASE[(leftchar&3) << 4];
ret += PAD + PAD;
} else if (leftbits == 4) {
ret += BASE[(leftchar&0xf) << 2];
ret += PAD;
}
return ret;
}

for (var i = 0; i < wav.length; i++) {
wav[i] = unSign(wav[i], 8);
}

document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
document.getElementById("player").play();
this['ret'] = new Uint8Array(FS.root.contents['wav.wav'].contents);

3 changes: 2 additions & 1 deletion src/shell_post.js
@@ -1,3 +1,4 @@
}).call({ text: text, args: args });
}).call(self);
return self.ret;
}

3 changes: 2 additions & 1 deletion src/shell_pre.js
@@ -1,4 +1,5 @@
// eSpeak and other code here are under the GNU GPL.
function speak(text, args) {
function generateSpeech(text, args) {
var self = { text: text, args: args, ret: null };
(function() {

0 comments on commit f62f0be

Please sign in to comment.