Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor speak.js into speakClient.js and speakGenerator.js
- Loading branch information
Showing
8 changed files
with
44 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
}).call({ text: text, args: args }); | ||
}).call(self); | ||
return self.ret; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|