Skip to main content
sharonhuston23
Known Participant
March 29, 2018
Question

Detect Audio with JavaScript (not Actions)

  • March 29, 2018
  • 3 replies
  • 2045 views

I'm working on an external script (not an action) that will parse a timed text file to display closed captions in Captivate. It's about halfway finished -- I can parse the file, and load the captions into a <div> I created.  (Yippie!)  The problem is that I want the captions to start automatically when the audio on the timeline plays. Right now the captions start when a new slide loads.  Sometimes, however, our audio doesn't start immediately, so everything gets out of sync. 

The Common JavaScript Interface doesn't seem to have anything I can use, so I've resorted to playing with the CMP file, and I'm completely lost.  Can anyone help me get started?  Does anyone know what part of the code controls audio?

Thanks,

Sharon

This topic has been closed for replies.

3 replies

Jeremy Shimmerman
Participating Frequently
April 6, 2018

When you import an audio file into Captivate, it renames it as a random number and stores it in the /ar folder.

If you want to control audio using js, you need to manually place your .mp3 files in the /ar folder.  The script to controlling the audio is:

cp.playAudio('filenamewithoutsuffix')

cp.stopAudio('filenamewithoutsuffix')

Hope that helps.  

Inspiring
February 12, 2020

And if you replace your audio files in the SCORM package afterwards you will also be able to deliver better sound quality as the files will not be further compressed.

/Jacob

eLearning_Pundits
Participating Frequently
April 3, 2018

Hey Sharon, I checked your question earlier but didn't really gave a thought. Sorry about that.

Now, I am not into JS developer but I just read your original question a bit carefully and tried to get it work using Advance Actions. Answer to your question

The problem is that I want the captions to start automatically when the audio on the timeline plays. Right now the captions start when a new slide loads.  Sometimes, however, our audio doesn't start immediately, so everything gets out of sync. 

could be here in screenshot below. it worked for me, let me know if I get it correctly. Or may be I didn't get your question and you don't want to use advance actions.

I have applied the action below on enter while keeping the default CC disabled:

Check the preview for the same project.

https://elearningpundits.com/cp_uploads/demo_projects/

RodWard
Community Expert
Community Expert
April 3, 2018

To be quite honest, I think using specialised Javascripting for this is way overkill.

If you don't want to use the Closed Captioning system that is built into Captivate (which works perfectly well), and you want to add your own captions instead, then just using Object Audio on those captions would be a lot simpler that trying to code in JS.  That way the audio would be loading and playing at exactly the same time as the captions entered the timeline.

eLearning_Pundits
Participating Frequently
April 3, 2018

Totally agree with RodWard

sharonhuston23
Known Participant
April 3, 2018

I'm making very slow progress.

  • cp.model.audios is an object that holds the name of the audio files.
  • cp.model.data holds several audio objects, all named with a pattern StAd#.

Neither of these objects seems to associate a slide with a particular audio file.  That association would be helpful.  At some point I'll want to say something like "If the audio on Slide 5 is playing, then show the closed captions."  It would help to know what Captivate named the audio on Slide 5.

I also found an AudioObject, and an AudioManager, but I'm not sure what they do.  Common sense says the AudioObject has information about a specific piece of audio, while the AudioManager plays/pauses/stops the audio, but I'm not sure yet. 

I'm also trying to manipulate the audio objects in the console using cp.stopAudio and cp.playAudio, but I'm not having any luck.  Any help is appreciated.