Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Playing Audio Using Keystrokes: Is It Possible?

Annabelle5893

Gold Coder
I'm wondering, how would I make an app that plays audio files using the keys on the number pad? Specifically, I want to make an app that triggers "Rotary Pulse 1" by pressing 1 on the numeric keypad, all the way up to "Rotary Pulse 0" on the 0 key. A dial tone will be toggled on by pressing the spacebar, which will begin with a "receiver pickup" noise. The dial tone turns off when digits are dialed via the numeric keypad. If you press the spacebar either when the dial tone is on, or after dialing a number, a "Receiver Hang Up" noise will be triggered. With the rotary dial sounds, the dial turning to the fingerhole is triggered at key down, and the release of the dial returning to the resting position will be triggered by releasing of the number corresponding to the fingerhole (1, 2, 3, 4, 5, 6, 7, 8, 9, 0). This will be accompanied by the internal sound of the dial pulses as heard in a telephone. What is the code I would use to make this audio app using HTML?
 
Can you unminify all of your code, that is, can you expand all of your code, and paste it all here? I think last time there was a cut-off and not all the code was posted. I had to go in and add a few closing braces towards the end just to make it valid js code. Once you expand all of it, the issue should be easier to identify.
Sure! Here you are! I think you said you want just the Javascript, right? Or do you also want the HTML?
Code:
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
<Title>Virtual Phone</Title>
</HEAD>
<BODY>
<div role="switch" aria-labelledby="id-label">
  <label for="Hookswitch Status"
  <button type="button"
          role="switch"
  id="hookswitch">Hookswitch Status
    <span class="on" aria-hidden="true">
      On
    </span>
    <span class="off" aria-hidden="true">
      Off
    </span>
  </label>
  </button>
</div>
<audio id="USADialtone" src="Call Progress Tones/Dial Tone/USA Dial Tone.ogg"></audio>
<audio id="VacantLevelTone" src="Call Progress Tones/Vacant Level Tone/Vacant Level Tone 1.ogg"></audio>
<audio id="DTMFToneDial1" src="DTMF Tone Dials/DTMF Tone Dial 1.ogg"</audio>
<audio id="DTMFToneDial2" src="DTMF Tone Dials/DTMF Tone Dial 2.ogg"</audio>
<audio id="DTMFToneDial3" src="DTMF Tone Dials/DTMF Tone Dial 3.ogg"</audio>
<audio id="DTMFToneDial4" src="DTMF Tone Dials/DTMF Tone Dial 4.ogg"</audio>
<audio id="DTMFToneDial5" src="DTMF Tone Dials/DTMF Tone Dial 5.ogg"</audio>
<audio id="DTMFToneDial6" src="DTMF Tone Dials/DTMF Tone Dial 6.ogg"</audio>
<audio id="DTMFToneDial7" src="DTMF Tone Dials/DTMF Tone Dial 7.ogg"</audio>
<audio id="DTMFToneDial8" src="DTMF Tone Dials/DTMF Tone Dial 8.ogg"</audio>
<audio id="DTMFToneDial9" src="DTMF Tone Dials/DTMF Tone Dial 9.ogg"</audio>
<audio id="DTMFToneDialStar" src="DTMF Tone Dials/DTMF Tone Dial Star.ogg"</audio>
<audio id="DTMFToneDial0" src="DTMF Tone Dials/DTMF Tone Dial 0.ogg"</audio>
<audio id="DTMFToneDialPound" src="DTMF Tone Dials/DTMF Tone Dial Pound.ogg"</audio>
<audio id="OneSlotUSAPayphoneNickelTone" src="One-Slot Payphone/USA Payphone Nickel Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneDimeTone" src="One-Slot Payphone/USA Payphone Dime Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneQuarterTone" src="One-Slot Payphone/USA Payphone Quarter Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneHalfDollarTone" src="One-Slot Payphone/USA Payphone Half Dollar Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneDollarTone" src="One-Slot Payphone/USA Payphone Dollar Tone.ogg"></audio>
<div id="ACTS">>
<center><p class="TONETYPE">1-SLOT COIN DEPOSIT SOUNDS</p></center>
<button id="ACTS5">$0.05</button>
<button id="ACTS10">$0.10</button>
<button id="ACTS25">$0.25</button>
</div>

<script>
function reload(){location.reload(true);}
var allowDial;allowDial=true;var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309","1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950","970-3920","1 (714) 733-9969","*57","*69"];function numberSuggestion(){var randomNumber=Math.floor(Math.random()*(availableNumbers.length));var suggestedNumber=availableNumbers[randomNumber];document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+suggestedNumber+"</strong>? Don't like this number? Click the button above again!";}
var dialTone;var isOffHook=false;var callIncoming=false;function receiverRaised(){if(allowDial===false){telephoneAnswered();}
else{offHook();}}
setCallTimeout();function setCallTimeout(){var delay=5000;var delayCaller=Math.floor((Math.random()*8000)+1);delay=delay+delayCaller;setTimeout(incomingCall,delay);}
function ringTelephone(){
   //code for this function here
}

function incomingCall(){
    ringTelephone();

    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
function dial1(){if(allowDial){numberDial();number=number+"1";var tone1=new Audio('DTMF Dials/DTMF Tone Dial 1.ogg');tone1.play();}}
function dial2(){if(allowDial){numberDial();number=number+"2";var tone2=new Audio('DTMF Tone Dials/DTMF Tone Dial 2.ogg');tone2.play();}}
function dial3(){if(allowDial){numberDial();number=number+"3";var tone3=new Audio('DTMF Tone Dials/DTMF Tone Dial 3.ogg');tone3.play();}}
function dial4(){if(allowDial){numberDial();number=number+"4";var tone4=new Audio('DTMF Tone Dials/DTMF Tone Dial 4.ogg');tone4.play();}}
function dial5(){if(allowDial){numberDial();number=number+"5";var tone5=new Audio('DTMF Tone Dials/DTMF Tone Dial 5.ogg');tone5.play();}}
function dial6(){if(allowDial){numberDial();number=number+"6";var tone6=new Audio('DTMF Tone Dials/DTMF Tone Dial 6.ogg');tone6.play();}}
function dial7(){if(allowDial){numberDial();number=number+"7";var tone7=new Audio('DTMF Tone Dials/DTMF Tone Dial 7.ogg');tone7.play();}}
function dial8(){if(allowDial){numberDial();number=number+"8";var tone8=new Audio('DTMF Tone Dials/DTMF Tone Dial 8.ogg');tone8.play();}}
function dial9(){if(allowDial){numberDial();number=number+"9";var tone9=new Audio('DTMF Tone Dials/DTMF Tone Dial 9.ogg');tone9.play();}}
function dial0(){if(allowDial){numberDial();number=number+"0";var tone0=new Audio('DTMF Tone Dials/DTMF Tone Dial 0.ogg');tone0.play();}}
function dialStar(){if(allowDial){numberDial();number=number+"*";var toneStar=new Audio('DTMF Tone Dials/DTMF Tone Dial Star.ogg');toneStar.play();}}
function dialPound(){if(allowDial){numberDial();number=number+"#";var tonePound=new Audio('DTMF Tone Dials/DTMF Tone Dial Pound.ogg');tonePound.play();}}
document.onkeydown=function(e){var key=e.keyCode?e.keyCode:e.which;if(e.which===48||e.which===96){dial0();}
if(e.which===49||e.which===97){dial1();}
if(e.which===50||e.which===98){dial2();}
if(e.which===51||e.which===99){dial3();}
if(e.which===52||e.which===100){dial4();}
if(e.which===53||e.which===101){dial5();}
if(e.which===54||e.which===102){dial6();}
if(e.which===55||e.which===103){dial7();}
if(e.which===56||e.which===104){dial8();}
if(e.which===57||e.which===105){dial9();}
if(e.which===106){dialStar();}
if(e.which==109){dialPound();}}
var ringingTone=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var timesRung=0;function dial(){allowDial=false;function ring(){ringingTone.play();timesRung++;if(timesRung>1){setTimeout(response,700);}}
ring();setTimeout(ring,4000);}
function response(){switch(number){case "0":var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');operatorPickup.addEventListener("ended",function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");if(number==null){number="0";}
operatorPutCallThrough();});operatorPickup.play();break;case "611":var pickup611=new Audio('callResponses/611.wav');pickup611.addEventListener("ended",function(){timeoutHowler();});pickup611.play();break;case "711":var pickup711=new Audio('callResponses/tdd-1.mp3');pickup711.play();break;case "811":var pickup611=new Audio('callResponses/811.wav');pickup811.addEventListener("ended",function(){timeoutHowler();});pickup811.play();break;case "911":var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');pickup911.addEventListener("ended",function(){timeoutHowler();});pickup911.play();break;case "18477651008":var pickupMCI=new Audio('callResponses/MCI.wav');pickupMCI.play();break;case "8675309":var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');pickup8675309.addEventListener("ended",function(){timeoutHowler();});pickup8675309.play();break;case "12124561414":busy();break;case "5551212":busy();break;case "5555555":var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');pickup5555555.addEventListener("ended",function(){timeoutHowler();});pickup5555555.play();break;case "7480900":var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');pickupSelf.play();break;case "18005820655":busy();break;case "6508950":var pickupAM=new Audio('callResponses/answering-machine-1.mp3');pickupAM.play();break;case "6500050":var pickupModem=new Audio('modem.wav');pickupModem.play();break;case "9703920":var pickupFax=new Audio('fax-1.mp3');pickupFax.play();break;case "17147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*8217147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*6717147339969":var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');pickup714block.addEventListener("ended",function(){timeoutHowler();});pickup714block.play();break;case "*57":var randNum57=Math.random()>=0.5;if(randNum57){var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');}
else{var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');}
pickupCallTrace.addEventListener("ended",function(){timeoutHowler();});pickupCallTrace.play();break;case "*69":var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');pickupStar69.addEventListener("ended",function(){timeoutHowler();});pickupStar69.play();break;case "police":var pickupPolice=new Audio('callResponses/policePickup.wav');pickupPolice.addEventListener("ended",function(){var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");confirm("Really? You say that "+policeComplaint);var policeHangup=new Audio('callResponses/policeHangup.wav');policeHangup.addEventListener("ended",function(){timeoutHowler();});policeHangup.play();});pickupPolice.play();break;default:var pickupDefault;if(number.length>7){pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');}
else{pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');}
pickupDefault.addEventListener("ended",function(){timeoutHowler();});pickupDefault.play();}}
function busy
</script>

</BODY>
</HTML>
 
Sure! Here you are! I think you said you want just the Javascript, right? Or do you also want the HTML?
Code:
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
<Title>Virtual Phone</Title>
</HEAD>
<BODY>
<div role="switch" aria-labelledby="id-label">
  <label for="Hookswitch Status"
  <button type="button"
          role="switch"
  id="hookswitch">Hookswitch Status
    <span class="on" aria-hidden="true">
      On
    </span>
    <span class="off" aria-hidden="true">
      Off
    </span>
  </label>
  </button>
</div>
<audio id="USADialtone" src="Call Progress Tones/Dial Tone/USA Dial Tone.ogg"></audio>
<audio id="VacantLevelTone" src="Call Progress Tones/Vacant Level Tone/Vacant Level Tone 1.ogg"></audio>
<audio id="DTMFToneDial1" src="DTMF Tone Dials/DTMF Tone Dial 1.ogg"</audio>
<audio id="DTMFToneDial2" src="DTMF Tone Dials/DTMF Tone Dial 2.ogg"</audio>
<audio id="DTMFToneDial3" src="DTMF Tone Dials/DTMF Tone Dial 3.ogg"</audio>
<audio id="DTMFToneDial4" src="DTMF Tone Dials/DTMF Tone Dial 4.ogg"</audio>
<audio id="DTMFToneDial5" src="DTMF Tone Dials/DTMF Tone Dial 5.ogg"</audio>
<audio id="DTMFToneDial6" src="DTMF Tone Dials/DTMF Tone Dial 6.ogg"</audio>
<audio id="DTMFToneDial7" src="DTMF Tone Dials/DTMF Tone Dial 7.ogg"</audio>
<audio id="DTMFToneDial8" src="DTMF Tone Dials/DTMF Tone Dial 8.ogg"</audio>
<audio id="DTMFToneDial9" src="DTMF Tone Dials/DTMF Tone Dial 9.ogg"</audio>
<audio id="DTMFToneDialStar" src="DTMF Tone Dials/DTMF Tone Dial Star.ogg"</audio>
<audio id="DTMFToneDial0" src="DTMF Tone Dials/DTMF Tone Dial 0.ogg"</audio>
<audio id="DTMFToneDialPound" src="DTMF Tone Dials/DTMF Tone Dial Pound.ogg"</audio>
<audio id="OneSlotUSAPayphoneNickelTone" src="One-Slot Payphone/USA Payphone Nickel Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneDimeTone" src="One-Slot Payphone/USA Payphone Dime Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneQuarterTone" src="One-Slot Payphone/USA Payphone Quarter Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneHalfDollarTone" src="One-Slot Payphone/USA Payphone Half Dollar Tone.ogg"></audio>
<audio id="OneSlotUSAPayphoneDollarTone" src="One-Slot Payphone/USA Payphone Dollar Tone.ogg"></audio>
<div id="ACTS">>
<center><p class="TONETYPE">1-SLOT COIN DEPOSIT SOUNDS</p></center>
<button id="ACTS5">$0.05</button>
<button id="ACTS10">$0.10</button>
<button id="ACTS25">$0.25</button>
</div>

<script>
function reload(){location.reload(true);}
var allowDial;allowDial=true;var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309","1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950","970-3920","1 (714) 733-9969","*57","*69"];function numberSuggestion(){var randomNumber=Math.floor(Math.random()*(availableNumbers.length));var suggestedNumber=availableNumbers[randomNumber];document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+suggestedNumber+"</strong>? Don't like this number? Click the button above again!";}
var dialTone;var isOffHook=false;var callIncoming=false;function receiverRaised(){if(allowDial===false){telephoneAnswered();}
else{offHook();}}
setCallTimeout();function setCallTimeout(){var delay=5000;var delayCaller=Math.floor((Math.random()*8000)+1);delay=delay+delayCaller;setTimeout(incomingCall,delay);}
function ringTelephone(){
   //code for this function here
}

function incomingCall(){
    ringTelephone();

    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
function dial1(){if(allowDial){numberDial();number=number+"1";var tone1=new Audio('DTMF Dials/DTMF Tone Dial 1.ogg');tone1.play();}}
function dial2(){if(allowDial){numberDial();number=number+"2";var tone2=new Audio('DTMF Tone Dials/DTMF Tone Dial 2.ogg');tone2.play();}}
function dial3(){if(allowDial){numberDial();number=number+"3";var tone3=new Audio('DTMF Tone Dials/DTMF Tone Dial 3.ogg');tone3.play();}}
function dial4(){if(allowDial){numberDial();number=number+"4";var tone4=new Audio('DTMF Tone Dials/DTMF Tone Dial 4.ogg');tone4.play();}}
function dial5(){if(allowDial){numberDial();number=number+"5";var tone5=new Audio('DTMF Tone Dials/DTMF Tone Dial 5.ogg');tone5.play();}}
function dial6(){if(allowDial){numberDial();number=number+"6";var tone6=new Audio('DTMF Tone Dials/DTMF Tone Dial 6.ogg');tone6.play();}}
function dial7(){if(allowDial){numberDial();number=number+"7";var tone7=new Audio('DTMF Tone Dials/DTMF Tone Dial 7.ogg');tone7.play();}}
function dial8(){if(allowDial){numberDial();number=number+"8";var tone8=new Audio('DTMF Tone Dials/DTMF Tone Dial 8.ogg');tone8.play();}}
function dial9(){if(allowDial){numberDial();number=number+"9";var tone9=new Audio('DTMF Tone Dials/DTMF Tone Dial 9.ogg');tone9.play();}}
function dial0(){if(allowDial){numberDial();number=number+"0";var tone0=new Audio('DTMF Tone Dials/DTMF Tone Dial 0.ogg');tone0.play();}}
function dialStar(){if(allowDial){numberDial();number=number+"*";var toneStar=new Audio('DTMF Tone Dials/DTMF Tone Dial Star.ogg');toneStar.play();}}
function dialPound(){if(allowDial){numberDial();number=number+"#";var tonePound=new Audio('DTMF Tone Dials/DTMF Tone Dial Pound.ogg');tonePound.play();}}
document.onkeydown=function(e){var key=e.keyCode?e.keyCode:e.which;if(e.which===48||e.which===96){dial0();}
if(e.which===49||e.which===97){dial1();}
if(e.which===50||e.which===98){dial2();}
if(e.which===51||e.which===99){dial3();}
if(e.which===52||e.which===100){dial4();}
if(e.which===53||e.which===101){dial5();}
if(e.which===54||e.which===102){dial6();}
if(e.which===55||e.which===103){dial7();}
if(e.which===56||e.which===104){dial8();}
if(e.which===57||e.which===105){dial9();}
if(e.which===106){dialStar();}
if(e.which==109){dialPound();}}
var ringingTone=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var timesRung=0;function dial(){allowDial=false;function ring(){ringingTone.play();timesRung++;if(timesRung>1){setTimeout(response,700);}}
ring();setTimeout(ring,4000);}
function response(){switch(number){case "0":var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');operatorPickup.addEventListener("ended",function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");if(number==null){number="0";}
operatorPutCallThrough();});operatorPickup.play();break;case "611":var pickup611=new Audio('callResponses/611.wav');pickup611.addEventListener("ended",function(){timeoutHowler();});pickup611.play();break;case "711":var pickup711=new Audio('callResponses/tdd-1.mp3');pickup711.play();break;case "811":var pickup611=new Audio('callResponses/811.wav');pickup811.addEventListener("ended",function(){timeoutHowler();});pickup811.play();break;case "911":var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');pickup911.addEventListener("ended",function(){timeoutHowler();});pickup911.play();break;case "18477651008":var pickupMCI=new Audio('callResponses/MCI.wav');pickupMCI.play();break;case "8675309":var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');pickup8675309.addEventListener("ended",function(){timeoutHowler();});pickup8675309.play();break;case "12124561414":busy();break;case "5551212":busy();break;case "5555555":var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');pickup5555555.addEventListener("ended",function(){timeoutHowler();});pickup5555555.play();break;case "7480900":var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');pickupSelf.play();break;case "18005820655":busy();break;case "6508950":var pickupAM=new Audio('callResponses/answering-machine-1.mp3');pickupAM.play();break;case "6500050":var pickupModem=new Audio('modem.wav');pickupModem.play();break;case "9703920":var pickupFax=new Audio('fax-1.mp3');pickupFax.play();break;case "17147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*8217147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*6717147339969":var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');pickup714block.addEventListener("ended",function(){timeoutHowler();});pickup714block.play();break;case "*57":var randNum57=Math.random()>=0.5;if(randNum57){var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');}
else{var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');}
pickupCallTrace.addEventListener("ended",function(){timeoutHowler();});pickupCallTrace.play();break;case "*69":var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');pickupStar69.addEventListener("ended",function(){timeoutHowler();});pickupStar69.play();break;case "police":var pickupPolice=new Audio('callResponses/policePickup.wav');pickupPolice.addEventListener("ended",function(){var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");confirm("Really? You say that "+policeComplaint);var policeHangup=new Audio('callResponses/policeHangup.wav');policeHangup.addEventListener("ended",function(){timeoutHowler();});policeHangup.play();});pickupPolice.play();break;default:var pickupDefault;if(number.length>7){pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');}
else{pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');}
pickupDefault.addEventListener("ended",function(){timeoutHowler();});pickupDefault.play();}}
function busy
</script>

</BODY>
</HTML>
Just the javascript.
 
Just the javascript.
Sure thing! Here ya go!
JavaScript:
<script>
function reload(){location.reload(true);}
var allowDial;allowDial=true;var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309","1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950","970-3920","1 (714) 733-9969","*57","*69"];function numberSuggestion(){var randomNumber=Math.floor(Math.random()*(availableNumbers.length));var suggestedNumber=availableNumbers[randomNumber];document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+suggestedNumber+"</strong>? Don't like this number? Click the button above again!";}
var dialTone;var isOffHook=false;var callIncoming=false;function receiverRaised(){if(allowDial===false){telephoneAnswered();}
else{offHook();}}
setCallTimeout();function setCallTimeout(){var delay=5000;var delayCaller=Math.floor((Math.random()*8000)+1);delay=delay+delayCaller;setTimeout(incomingCall,delay);}
function ringTelephone(){
   //code for this function here
}

function incomingCall(){
    ringTelephone();

    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
function dial1(){if(allowDial){numberDial();number=number+"1";var tone1=new Audio('DTMF Dials/DTMF Tone Dial 1.ogg');tone1.play();}}
function dial2(){if(allowDial){numberDial();number=number+"2";var tone2=new Audio('DTMF Tone Dials/DTMF Tone Dial 2.ogg');tone2.play();}}
function dial3(){if(allowDial){numberDial();number=number+"3";var tone3=new Audio('DTMF Tone Dials/DTMF Tone Dial 3.ogg');tone3.play();}}
function dial4(){if(allowDial){numberDial();number=number+"4";var tone4=new Audio('DTMF Tone Dials/DTMF Tone Dial 4.ogg');tone4.play();}}
function dial5(){if(allowDial){numberDial();number=number+"5";var tone5=new Audio('DTMF Tone Dials/DTMF Tone Dial 5.ogg');tone5.play();}}
function dial6(){if(allowDial){numberDial();number=number+"6";var tone6=new Audio('DTMF Tone Dials/DTMF Tone Dial 6.ogg');tone6.play();}}
function dial7(){if(allowDial){numberDial();number=number+"7";var tone7=new Audio('DTMF Tone Dials/DTMF Tone Dial 7.ogg');tone7.play();}}
function dial8(){if(allowDial){numberDial();number=number+"8";var tone8=new Audio('DTMF Tone Dials/DTMF Tone Dial 8.ogg');tone8.play();}}
function dial9(){if(allowDial){numberDial();number=number+"9";var tone9=new Audio('DTMF Tone Dials/DTMF Tone Dial 9.ogg');tone9.play();}}
function dial0(){if(allowDial){numberDial();number=number+"0";var tone0=new Audio('DTMF Tone Dials/DTMF Tone Dial 0.ogg');tone0.play();}}
function dialStar(){if(allowDial){numberDial();number=number+"*";var toneStar=new Audio('DTMF Tone Dials/DTMF Tone Dial Star.ogg');toneStar.play();}}
function dialPound(){if(allowDial){numberDial();number=number+"#";var tonePound=new Audio('DTMF Tone Dials/DTMF Tone Dial Pound.ogg');tonePound.play();}}
document.onkeydown=function(e){var key=e.keyCode?e.keyCode:e.which;if(e.which===48||e.which===96){dial0();}
if(e.which===49||e.which===97){dial1();}
if(e.which===50||e.which===98){dial2();}
if(e.which===51||e.which===99){dial3();}
if(e.which===52||e.which===100){dial4();}
if(e.which===53||e.which===101){dial5();}
if(e.which===54||e.which===102){dial6();}
if(e.which===55||e.which===103){dial7();}
if(e.which===56||e.which===104){dial8();}
if(e.which===57||e.which===105){dial9();}
if(e.which===106){dialStar();}
if(e.which==109){dialPound();}}
var ringingTone=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var timesRung=0;function dial(){allowDial=false;function ring(){ringingTone.play();timesRung++;if(timesRung>1){setTimeout(response,700);}}
ring();setTimeout(ring,4000);}
function response(){switch(number){case "0":var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');operatorPickup.addEventListener("ended",function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");if(number==null){number="0";}
operatorPutCallThrough();});operatorPickup.play();break;case "611":var pickup611=new Audio('callResponses/611.wav');pickup611.addEventListener("ended",function(){timeoutHowler();});pickup611.play();break;case "711":var pickup711=new Audio('callResponses/tdd-1.mp3');pickup711.play();break;case "811":var pickup611=new Audio('callResponses/811.wav');pickup811.addEventListener("ended",function(){timeoutHowler();});pickup811.play();break;case "911":var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');pickup911.addEventListener("ended",function(){timeoutHowler();});pickup911.play();break;case "18477651008":var pickupMCI=new Audio('callResponses/MCI.wav');pickupMCI.play();break;case "8675309":var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');pickup8675309.addEventListener("ended",function(){timeoutHowler();});pickup8675309.play();break;case "12124561414":busy();break;case "5551212":busy();break;case "5555555":var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');pickup5555555.addEventListener("ended",function(){timeoutHowler();});pickup5555555.play();break;case "7480900":var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');pickupSelf.play();break;case "18005820655":busy();break;case "6508950":var pickupAM=new Audio('callResponses/answering-machine-1.mp3');pickupAM.play();break;case "6500050":var pickupModem=new Audio('modem.wav');pickupModem.play();break;case "9703920":var pickupFax=new Audio('fax-1.mp3');pickupFax.play();break;case "17147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*8217147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*6717147339969":var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');pickup714block.addEventListener("ended",function(){timeoutHowler();});pickup714block.play();break;case "*57":var randNum57=Math.random()>=0.5;if(randNum57){var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');}
else{var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');}
pickupCallTrace.addEventListener("ended",function(){timeoutHowler();});pickupCallTrace.play();break;case "*69":var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');pickupStar69.addEventListener("ended",function(){timeoutHowler();});pickupStar69.play();break;case "police":var pickupPolice=new Audio('callResponses/policePickup.wav');pickupPolice.addEventListener("ended",function(){var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");confirm("Really? You say that "+policeComplaint);var policeHangup=new Audio('callResponses/policeHangup.wav');policeHangup.addEventListener("ended",function(){timeoutHowler();});policeHangup.play();});pickupPolice.play();break;default:var pickupDefault;if(number.length>7){pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');}
else{pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');}
pickupDefault.addEventListener("ended",function(){timeoutHowler();});pickupDefault.play();}}
function busy
</script>
 
Sure thing! Here ya go!
JavaScript:
<script>
function reload(){location.reload(true);}
var allowDial;allowDial=true;var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309","1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950","970-3920","1 (714) 733-9969","*57","*69"];function numberSuggestion(){var randomNumber=Math.floor(Math.random()*(availableNumbers.length));var suggestedNumber=availableNumbers[randomNumber];document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+suggestedNumber+"</strong>? Don't like this number? Click the button above again!";}
var dialTone;var isOffHook=false;var callIncoming=false;function receiverRaised(){if(allowDial===false){telephoneAnswered();}
else{offHook();}}
setCallTimeout();function setCallTimeout(){var delay=5000;var delayCaller=Math.floor((Math.random()*8000)+1);delay=delay+delayCaller;setTimeout(incomingCall,delay);}
function ringTelephone(){
   //code for this function here
}

function incomingCall(){
    ringTelephone();

    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
function dial1(){if(allowDial){numberDial();number=number+"1";var tone1=new Audio('DTMF Dials/DTMF Tone Dial 1.ogg');tone1.play();}}
function dial2(){if(allowDial){numberDial();number=number+"2";var tone2=new Audio('DTMF Tone Dials/DTMF Tone Dial 2.ogg');tone2.play();}}
function dial3(){if(allowDial){numberDial();number=number+"3";var tone3=new Audio('DTMF Tone Dials/DTMF Tone Dial 3.ogg');tone3.play();}}
function dial4(){if(allowDial){numberDial();number=number+"4";var tone4=new Audio('DTMF Tone Dials/DTMF Tone Dial 4.ogg');tone4.play();}}
function dial5(){if(allowDial){numberDial();number=number+"5";var tone5=new Audio('DTMF Tone Dials/DTMF Tone Dial 5.ogg');tone5.play();}}
function dial6(){if(allowDial){numberDial();number=number+"6";var tone6=new Audio('DTMF Tone Dials/DTMF Tone Dial 6.ogg');tone6.play();}}
function dial7(){if(allowDial){numberDial();number=number+"7";var tone7=new Audio('DTMF Tone Dials/DTMF Tone Dial 7.ogg');tone7.play();}}
function dial8(){if(allowDial){numberDial();number=number+"8";var tone8=new Audio('DTMF Tone Dials/DTMF Tone Dial 8.ogg');tone8.play();}}
function dial9(){if(allowDial){numberDial();number=number+"9";var tone9=new Audio('DTMF Tone Dials/DTMF Tone Dial 9.ogg');tone9.play();}}
function dial0(){if(allowDial){numberDial();number=number+"0";var tone0=new Audio('DTMF Tone Dials/DTMF Tone Dial 0.ogg');tone0.play();}}
function dialStar(){if(allowDial){numberDial();number=number+"*";var toneStar=new Audio('DTMF Tone Dials/DTMF Tone Dial Star.ogg');toneStar.play();}}
function dialPound(){if(allowDial){numberDial();number=number+"#";var tonePound=new Audio('DTMF Tone Dials/DTMF Tone Dial Pound.ogg');tonePound.play();}}
document.onkeydown=function(e){var key=e.keyCode?e.keyCode:e.which;if(e.which===48||e.which===96){dial0();}
if(e.which===49||e.which===97){dial1();}
if(e.which===50||e.which===98){dial2();}
if(e.which===51||e.which===99){dial3();}
if(e.which===52||e.which===100){dial4();}
if(e.which===53||e.which===101){dial5();}
if(e.which===54||e.which===102){dial6();}
if(e.which===55||e.which===103){dial7();}
if(e.which===56||e.which===104){dial8();}
if(e.which===57||e.which===105){dial9();}
if(e.which===106){dialStar();}
if(e.which==109){dialPound();}}
var ringingTone=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var timesRung=0;function dial(){allowDial=false;function ring(){ringingTone.play();timesRung++;if(timesRung>1){setTimeout(response,700);}}
ring();setTimeout(ring,4000);}
function response(){switch(number){case "0":var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');operatorPickup.addEventListener("ended",function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");if(number==null){number="0";}
operatorPutCallThrough();});operatorPickup.play();break;case "611":var pickup611=new Audio('callResponses/611.wav');pickup611.addEventListener("ended",function(){timeoutHowler();});pickup611.play();break;case "711":var pickup711=new Audio('callResponses/tdd-1.mp3');pickup711.play();break;case "811":var pickup611=new Audio('callResponses/811.wav');pickup811.addEventListener("ended",function(){timeoutHowler();});pickup811.play();break;case "911":var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');pickup911.addEventListener("ended",function(){timeoutHowler();});pickup911.play();break;case "18477651008":var pickupMCI=new Audio('callResponses/MCI.wav');pickupMCI.play();break;case "8675309":var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');pickup8675309.addEventListener("ended",function(){timeoutHowler();});pickup8675309.play();break;case "12124561414":busy();break;case "5551212":busy();break;case "5555555":var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');pickup5555555.addEventListener("ended",function(){timeoutHowler();});pickup5555555.play();break;case "7480900":var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');pickupSelf.play();break;case "18005820655":busy();break;case "6508950":var pickupAM=new Audio('callResponses/answering-machine-1.mp3');pickupAM.play();break;case "6500050":var pickupModem=new Audio('modem.wav');pickupModem.play();break;case "9703920":var pickupFax=new Audio('fax-1.mp3');pickupFax.play();break;case "17147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*8217147339969":var pickup714=new Audio('device-conference.mp3');pickup714.play();break;case "*6717147339969":var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');pickup714block.addEventListener("ended",function(){timeoutHowler();});pickup714block.play();break;case "*57":var randNum57=Math.random()>=0.5;if(randNum57){var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');}
else{var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');}
pickupCallTrace.addEventListener("ended",function(){timeoutHowler();});pickupCallTrace.play();break;case "*69":var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');pickupStar69.addEventListener("ended",function(){timeoutHowler();});pickupStar69.play();break;case "police":var pickupPolice=new Audio('callResponses/policePickup.wav');pickupPolice.addEventListener("ended",function(){var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");confirm("Really? You say that "+policeComplaint);var policeHangup=new Audio('callResponses/policeHangup.wav');policeHangup.addEventListener("ended",function(){timeoutHowler();});policeHangup.play();});pickupPolice.play();break;default:var pickupDefault;if(number.length>7){pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');}
else{pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');}
pickupDefault.addEventListener("ended",function(){timeoutHowler();});pickupDefault.play();}}
function busy
</script>
Question: that line just above the end script tag...is that supposed to be a new function?
 
Comment out? I'm confused! What's "Comment Out"?
in javascript, as with most modern coding languages, when you "comment out code", you are temporarily disabling the snippet of code. When you "add a comment", you are adding some kind of string either explaining what the snippet of code does or adding something helpful so that anyone looking at the code can quickly tell what the code does. There are 2 ways to add comments, single-line comments, and block-style comments:
JavaScript:
//this is a single-line comment

/*
 * this is a block-style comment. This is to be used when
 * you have to use multiple lines in order to describe the
 * code functionality/logic
 */

When commenting out code, if you are going to disable one line of code, use single-line style, otherwise if you are going to comment out multiple lines, use the block-style

JavaScript:
//var myABC = new Alphabet('lexicon');

/*
 * function Alphabet(string) {
 * var lex = string;
 * }
 */
 
Last edited:
in javascript, as with most modern coding languages, when you "comment out code", you are temporarily disabling the snippet of code. When you "add a comment", you are adding some kind of string either explaining what the snippet of code does or adding something helpful so that anyone looking at the code can quickly tell what the code does. There are 2 ways to add comments, single-line comments, and block-style comments:
JavaScript:
//this is a single-line comment

/*
 * this is a block-style comment. This is to be used when
 * you have to use multiple lines in order to describe the
 * code functionality/logic
 */

When commenting out code, if you are going to disable one line of code, use single-line style, otherwise if you are going to comment out multiple lines, use the block-style

JavaScript:
//var myABC = new Alphabet('lexicon');

/*
 * function Alphabet(string) {
 * var lex = string;
 * }
 */
So how would I "comment out" the line that says: function busy
 
Now that there are no errors, I still can't figure out why when I press the keys to play some audio, nothing happens. In other words, I can't hear any tones. Am I forgetting something?
View attachment 2206
two things:
1) do you have the path to the audio files correct?
2) do you get any errors in console when you click on something?

Side note: is that wireshark you are running in the background lol? Also, might wanna go ahead and update your machine...if you keep those updates there for too long, they will start to bog down your machine... don't help all the other programs you got running there 😀. Don't worry, my taskbar usually looks worse lol
 
two things:
1) do you have the path to the audio files correct?
2) do you get any errors in console when you click on something?

Side note: is that wireshark you are running in the background lol? Also, might wanna go ahead and update your machine...if you keep those updates there for too long, they will start to bog down your machine... don't help all the other programs you got running there 😀. Don't worry, my taskbar usually looks worse lol
I just recently performed some updates today. Also, Wireshark? What's that? Now that I think about it, there is at least one error. Line 62:9. Right now it says:
JavaScript:
ringRing.play();
I'm not sure what exactly the error is, though, because I believe I wrote it right. As for the file names, would this example look right?
HTML:
<audio id="USADialtone" src="Call Progress Tones/Dial Tone/USA Dial Tone.ogg"></audio>
 
I just recently performed some updates today. Also, Wireshark? What's that? Now that I think about it, there is at least one error. Line 62:9. Right now it says:
JavaScript:
ringRing.play();
I'm not sure what exactly the error is, though, because I believe I wrote it right. As for the file names, would this example look right?
HTML:
<audio id="USADialtone" src="Call Progress Tones/Dial Tone/USA Dial Tone.ogg"></audio>
ah... so I think the issue may be in the src attribute. One thing you should consider:
anytime there is a string in the src attribute, any slashes will be treated as directories...so for example
HTML:
<audio src="resources/audio/thisRingTone.ogg"></audio>
In this example, "resources" and "audio" are both directories. notice how the forward-slash proceeds them, and when we get to the file, "thisRingTone.ogg", the forward-slash precedes the file name. In your clase. In your case, "Call Progress Tones" and "Dial Tones" are assumed to be directories. One thing to note, is the spaces themselves. Not a good idea to have spaces anywhere in file/directory paths. You can overcome this one of 2 ways:
1) replace all space characters with "%20" (the space character in utf-8)
2) just don't have any spaces at all, and use PascalCaseWhenNamingThings
 
ah... so I think the issue may be in the src attribute. One thing you should consider:
anytime there is a string in the src attribute, any slashes will be treated as directories...so for example
HTML:
<audio src="resources/audio/thisRingTone.ogg"></audio>
In this example, "resources" and "audio" are both directories. notice how the forward-slash proceeds them, and when we get to the file, "thisRingTone.ogg", the forward-slash precedes the file name. In your clase. In your case, "Call Progress Tones" and "Dial Tones" are assumed to be directories. One thing to note, is the spaces themselves. Not a good idea to have spaces anywhere in file/directory paths. You can overcome this one of 2 ways:
1) replace all space characters with "%20" (the space character in utf-8)
2) just don't have any spaces at all, and use PascalCaseWhenNamingThings
So if I put something like:
HTML:
<audio id="USADialtone" src="Call%20Progress%20Tones/Dial%20Tone/USA%20Dial%20Tone.ogg"></audio>
That it would actually route to the Dial Tone file and play that when the app recognizes a press of the Spacebar?
 
So if I put something like:
HTML:
<audio id="USADialtone" src="Call%20Progress%20Tones/Dial%20Tone/USA%20Dial%20Tone.ogg"></audio>
That it would actually route to the Dial Tone file and play that when the app recognizes a press of the Spacebar?
If you have your event listener to listen for the spacebar and use that audio file, then yes, when the spacebar gets hit, the event listener should catch it and play the sound
 
Back
Top Bottom