Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
load worker immediately, and use it by default
  • Loading branch information
kripken committed Jan 13, 2012
1 parent 4ea90aa commit 8dd86c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo.html
Expand Up @@ -10,7 +10,7 @@
<body>
<h1>speak.js</h1>
<h2>Text-To-Speech on the Web</h2>
<form onsubmit="speak(text.value, { amplitude: amplitude.value, wordgap: workdgap.value, pitch: pitch.value, speed: speed.value, worker: true }); return false">
<form onsubmit="speak(text.value, { amplitude: amplitude.value, wordgap: workdgap.value, pitch: pitch.value, speed: speed.value }); return false">
Text: <input type="text" name="text" size=50 value="Never gonna give, you, up.">
Amplitude: <input type="text" name="amplitude" size=5 value="100">
Pitch: <input type="text" name="pitch" size=5 value="50">
Expand Down
1 change: 0 additions & 1 deletion helloworld.html
@@ -1,6 +1,5 @@
<html>
<head>
<script src="speakGenerator.js"></script>
<script src="speakClient.js"></script>
</head>
<body>
Expand Down
16 changes: 11 additions & 5 deletions speakClient.js
@@ -1,3 +1,10 @@
var speakWorker;
try {
speakWorker = new Worker('speakWorker.js');
} catch(e) {
console.log('speak.js warning: no worker support');
}

function speak(text, args) {
function parseWav(wav) {
function readInt(i, bytes) {
Expand Down Expand Up @@ -76,16 +83,15 @@ function speak(text, args) {
playHTMLAudioElement(wav);
}

if (!(args && args.worker)) {
if (args && args.noWorker) {
// Do everything right now. speakGenerator.js must have been loaded.
handleWav(generateSpeech(text, args));
} else {
// Call a worker, which will return a wav that we then play
var worker = new Worker('speakWorker.js');
worker.onmessage = function(event) {
// Call the worker, which will return a wav that we then play
speakWorker.onmessage = function(event) {
handleWav(event.data);
};
worker.postMessage({ text: text, args: args });
speakWorker.postMessage({ text: text, args: args });
}
}

0 comments on commit 8dd86c5

Please sign in to comment.