If you want to associate sfx with quotes you can do this:

var quotes = [];

quotes.push(
  { text: 'This is the quote text'
  , sfx: '/path/to/sound.ogg'
  }
, { text: 'Another text'
  , sfx: '/path/to/another.ogg'
  }
);

var quote = quotes[ Math.floor( Math.random() * quotes.length ) ];
document.getElementById('quote').innerHTML = quote.text;

var sfx = new Audio(quote.sfx);
sfx.play();

- stagas


2011/3/7 Sai Lung Wong <[email protected]>:
> If all you are looking to do is have something read out the text, then you
> can think about using the google Text to Speech engine.
> http://weston.ruter.net/projects/google-tts/
>
> On Sun, Mar 6, 2011 at 1:37 AM, Bryce <[email protected]> wrote:
>>
>> Hello,
>>
>> I'm looking for some help on how to add a sound effect to my current
>> javascript. I'm using a simple array of quotes to generate a new quote
>> each time a button is clicked. I'd like to also have an audio clip of
>> the quote to play in accordance with the text of the quote being
>> displayed. I'm a noob so I have no idea how to accomplish this. Any
>> help is greatly appreciated!
>>
>> Here's the basic structure of what I'm using now.
>>
>> var pullQuote = new Array(5);
>>
>> var randomNumber = Math.floor(Math.random() * 5);
>>
>> pullQuote[ 0] =  "I like Internet Scripting, but it is very hard and
>> sometimes makes my brain hurt!";
>> pullQuote[ 1] =  "Internet Scripting is the best course in the DMT
>> program!";
>> pullQuote[ 2] =  "Learning JavaScript will help me become a better web
>> designer!";
>> pullQuote[ 3] =  "I think JavaScript is for the monkeys!";
>> pullQuote[ 4] =  "JavaScript makes me go loopy!";
>>
>> var quote = document.getElementById('quote');
>>
>> quote.innerHTML = (pullQuote[randomNumber]);
>>
>> --
>> To view archived discussions from the original JSMentors Mailman list:
>> http://www.mail-archive.com/[email protected]/
>>
>> To search via a non-Google archive, visit here:
>> http://www.mail-archive.com/[email protected]/
>>
>> To unsubscribe from this group, send email to
>> [email protected]
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to