Skip to main content
Participating Frequently
July 8, 2014
Question

How to add closed captioning to audio not on the timeline?

  • July 8, 2014
  • 2 replies
  • 2092 views

Cp 7 - I'm using a drag and drop and am triggering audio to start when the user passes/fails the interaction. How can I add closed captioning to this audio as it's not on the timeline?

Thanks,

Angela

    This topic has been closed for replies.

    2 replies

    Known Participant
    March 22, 2016

    Hi! Old post I know, but here's a JavaScript solution I just worked out for adding CC text for triggered audio:

    This code inserts a new <p> element into the default CC text element and populates it with the CC text for your triggered audio clips. In my case there is slide audio that plays before the click boxes appear that trigger the "popup" audio. They were set to stop slide audio, but the default CC text was staying up, so my code had to hide it.

    Add Functions in a Common on Enter Slide Action:

    I put this (and other custom functions my course uses) in an advanced action that is is called by every slide in the on Enter action.

    - The CC text function:

    $('p.hideCPel').removeClass('hideCPel');//restore CC text to default style on other slides

    $('#altCCtxt').remove();//remove any previous alt CC text

    function createAltCC(cc) {

      var ccTxt = $('#ccText').find('p')[0];//link to default CC text element

      if(!$(ccTxt).hasClass('hideCPel')) {

      $(ccTxt).addClass('hideCPel');

      }

      $('#altCCtxt').remove();//remove previous CCs

      var altCCtxt=document.createElement('p');

      $('#ccText').prepend(altCCtxt);

      altCCtxt.id='altCCtxt';

      altCCtxt.innerHTML=cc;

    };//end createAltCC

    - Adding CSS styles:

    I discovered you can't just overwrite the existing CC text <p> element (you can but it keeps reverting), so my code adds a CSS class that hides it (the only way I've found to overwrite a Captivate element's inline styles).

    So this must be added to main slideEnter code (the addCSSRule function was generously offered by another forum user--this is just my utilization of it):

    if(!window.custCSS) {
    function addCSSRule(sheet, selector, rules, index) {
    if("insertRule" in sheet) {
    sheet.insertRule(selector + "{" + rules + "}", index);
    } else if("addRule" in sheet) {
    sheet.addRule(selector, rules, index);
    }
    }

    addCSSRule(document.styleSheets[0], "#altCCtxt", "margin-left:8px;margin-right:8px;margin-top:2px", 1);

    addCSSRule(document.styleSheets[0], ".hideCPel", "display:none !important; opacity: 0;", 1);

    window.custCSS=true;

    }//end custCSS if

    That custCSS if statement prevents the action from repeatedly adding the styles to your course's index.html file.

    Invoking the Function:

    - The alt CC text is applied by adding this code to an advanced action (the one that is triggering your audio):

    var ccText = 'This is your CC text for you triggered audio. It must be a simple text string like this--sorry, no line breaks or html tags.';

    createAltCC(ccText);

    Hope that helps somebody. ~t

    BTW, I actually also include these styles which re-positions the CC box into a scrollable sidebar:

    addCSSRule(document.styleSheets[0], "#cc", "background: #F0F0F0; opacity: 0.9;float: right !important; position: absolute !important; top: 64px !important; left: 1021px !important; width: 200px !important; height: 506px !important; bottom: 0px; z-index: 4; overflow-y: scroll; pointer-events: all !important", 1);

    addCSSRule(document.styleSheets[0], "#ccText", "padding-top: 5px", 1);

    addCSSRule(document.styleSheets[0], "#ccClose", "display: none", 1);

    birajawithu
    Participating Frequently
    October 29, 2018

    Hi buneznunez​,

    Thanks for the solution. I just followed your instruction and created a course executing the java script you provided. However, it's not working. Just for your info, I am not expert in Java Script and may be there is missing something in my code. Can you please share a sample captivate file having one slide for this. So that I can refer that one.

    Thanks in Advance,

    Biraja Prasanna

    Email: birajawithu@gmail.com

    Known Participant
    October 29, 2018

    Biraja, I've emailed you but I'll also reply here for future visitors.

    I’m glad you asked for help because it made me realize that Captivate 2017 made a change in the way it does CC text that broke my custom code for triggered audio CC text. (I haven’t done a course that had audio popups since we upgraded from CP 9.) I think I've fixed it now.

    The key is that now Captivate will only display the CC box when there is an active waveform on the slide. So even if you have a slide that only has triggered audio (i.e. it doesn’t have slide audio) you still have to have an audio clip; it can just contain silence.

    Or if there IS slide audio, you have to pause the slide before the audio clip runs out. Otherwise the CC box goes away. I haven't done it yet, but I envision adding some extra silence to the end of an audio clip and then pausing* before the silence runs out.

    *Here's the tricky part about pausing the slide: using the pause behavior in a button's timing doesn't seem to work (the slide will pause but the CC box goes away). I'm having to do it with an execute JavaScript action, which is part of a special slideEnter action I made for slides that will have popup audio.

           //pause the slide

            setTimeout(function() {window.cpAPIInterface.pause();}, 50);

    The 50 is milliseconds, so to pause a half second after a two second clip you would make it 2500.

    Good luck.

    xr42nv
    Inspiring
    July 9, 2014

    Hi Angela,

    Unfortunately you can't place captions on audio that is not assigned to the slide timeline. (so for example if your button 'plays audio' you cannot apply CC).

    The only way is the pause the slide timeline and add a continue button. Unfortunetly that won't help you with your situation.

    It has been one thing that has always annoyed me about CP, because all programs i build need to have CC under my accessibility requirement.

    RodWard
    Community Expert
    Community Expert
    July 9, 2014

    Your interaction has Success or Failure captions.  Put your CC text inside these captions and format/place them on the slide so that they look similar to the normal CC text.  Attach your audio to these captions as well.  This way, when your user succeeds or fails with your interaction, the success/failure captions will play the appropriate audio and the captions themselves will supply the CC on screen text.

    (NOTE: You may need to use advanced actions to hide the normal CC text while your drag and drop interaction is working otherwise your faux CC captions will be underneath the normal CC text area and therefore obscured.)

    anick421Author
    Participating Frequently
    July 9, 2014

    Hi Rod,

    Thanks, that's a great work around!