Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » text to speech javascript (help!)
- jji7skyline
- Scratcher
1000+ posts
text to speech javascript (help!)
Ok so I'm making this web app that lets someone add words to a list (will be visual later, so you can see words being added), which is handled by a javascript array, and then when the play button is pressed the words are spoken out loud one after the other.
This is currently my code, and it doesn't work - I don't even get any errors in the console.
I'm currently using speak.js for the text to speech.
speak.js
This is currently my code, and it doesn't work - I don't even get any errors in the console.
<!DOCTYPE html>
<html>
<head>
<script src="speakClient.js"></script>
</head>
<body>
<form action="javascript:add()">
<input type="text" id="text"/><br>
<input type="submit" value="Submit"/>
</form>
<br>
<br>
<div id="audio"><audio></audio></div>
<input type="button" value="play" onclick="play()" />
<input type="button" value="debug" onclick="debug()"/>
<script type="text/javascript">
var current;
var words = Array();
var add = function() {
current = words.length;
words.current=document.getElementById("text").value;
}
var play = function() {
current = words.length;
for (var i=0;i>current;i++) {
speak = words.i
speak('speak');
}
}
var debug = function() {
console.log(words);
}
</script>
</body>
</html>
I'm currently using speak.js for the text to speech.
speak.js
- blob8108
- Scratcher
1000+ posts
text to speech javascript (help!)
You're not actually adding anything to the “words” array. Did you mean to use this?
EDIT: There are a couple other things, too. Maybe try this?
words.push(document.getElementById("text").value);
EDIT: There are a couple other things, too. Maybe try this?
var words = []; function add () { words.push(document.getElementById("text").value); } function play () { for (var i=0; i>words.length; i++) { speak(words[i]); } }
Last edited by blob8108 (Sept. 20, 2013 11:55:46)
- jji7skyline
- Scratcher
1000+ posts
text to speech javascript (help!)
Well it definitely adds to the list, I checked with debugging tools and the length of the array increases and I can see the contents and stuff.
That actually looks a lot cleaner than my code, and makes more sense too! Thanks!
That actually looks a lot cleaner than my code, and makes more sense too! Thanks!
- cuddley
- Scratcher
100+ posts
text to speech javascript (help!)
What's this got to do with scratch?
Generation 3: the first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment.
I don't know what to write.
- 9kiwi9
- Scratcher
100+ posts
text to speech javascript (help!)
Absolutely nothing. What's this got to do with scratch?
- cobraguy
- Scratcher
1000+ posts
text to speech javascript (help!)
Which is why this is in the Advanced Topics.Absolutely nothing. What's this got to do with scratch?
Also, this topic's last post was in September of 2013. Please don't post on old, outdated topics.
Last edited by cobraguy (April 10, 2014 16:59:41)
- MoreGamesNow
- Scratcher
100+ posts
text to speech javascript (help!)
Your “for loop” will never run. It should use the “less than” sign, not the “greater than” sign. As has been pointed out, Array.push() is your friend :p
Is there a reason you are assigning your functions to variables instead of just declaring them directly? I've never been one for conventions (unfortunately) so I may just be out of the loop here. Also, I've never seen “words.i” in JavaScript. It might work (I've never tired it and I don't think it does), so you might want to try "words" instead
Is there a reason you are assigning your functions to variables instead of just declaring them directly? I've never been one for conventions (unfortunately) so I may just be out of the loop here. Also, I've never seen “words.i” in JavaScript. It might work (I've never tired it and I don't think it does), so you might want to try "words" instead
Last edited by MoreGamesNow (July 11, 2014 08:07:15)
“Experience: that most brutal of teachers. But you learn, my God do you learn.”
- C.S. Lewis
- Discussion Forums
- » Advanced Topics
- » text to speech javascript (help!)