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?
 
Hey there,
can you check the code inside of your ring() method?
Is this what you mean?
JavaScript:
var ringRing=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var hasTelephoneBeenAnswered=false;function incomingCall(){function ringTelephone(){if(!hasTelephoneBeenAnswered){ringRing.play();ringRing.currentTime=0;}}
if(isOffHook===false){ringRing.play();allowDial=false;callIncoming=true;setInterval(ringTelephone,5500);}}
 
JavaScript:
var ringRing=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');
var hasTelephoneBeenAnswered=false;
function incomingCall(){
    function ringTelephone(){
        if(!hasTelephoneBeenAnswered){
            ringRing.play();
            ringRing.currentTime=0;
        }
    }
    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
 
Is this what you mean?
JavaScript:
var ringRing=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');var hasTelephoneBeenAnswered=false;function incomingCall(){function ringTelephone(){if(!hasTelephoneBeenAnswered){ringRing.play();ringRing.currentTime=0;}}
if(isOffHook===false){ringRing.play();allowDial=false;callIncoming=true;setInterval(ringTelephone,5500);}}
yes, and word to the wise: minified code in general is great for performance... but horrible for debugging 🙂. Please make it a habit of working with the expanded version until you are ready for production. Trust me, it will not only save you the pains and the migraines, but those seeking to help out as well 🙂. Talking from personal experience here 😀
 
JavaScript:
var ringRing=new Audio('Ringing Tone/Princess 702B Bell Ring.ogg');
var hasTelephoneBeenAnswered=false;
function incomingCall(){
    function ringTelephone(){
        if(!hasTelephoneBeenAnswered){
            ringRing.play();
            ringRing.currentTime=0;
        }
    }
    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
This is the expanded version of your code...can you walk me/us through your logic here?
 
This is the expanded version of your code...can you walk me/us through your logic here?
If an incoming call comes in, the app will make the phone ring. To take it off hook, lift the receiver by pressing Spacebar, which would otherwise trigger a "Pick Up Phone" noise (external), a "Telephone Connect Noise" (Internal", and a "Dial Tone" if no incoming call is present on the screen. This is loosely based on the phones of the web sites, TouchTone Telephone Emulator, Rotary Telephone Emulator, and Virtual Blue Box. Only this time, mine will be fully functional and accessible to screenreaders. What I want to do is create a Virtual Phone app for entertainment and fun, which can let you dial either Rotary pulses, DTMF Tones, MF Tones, or even SF Tones, and also have options for hearing payphone tones right from your computer. The "Hookswitch Status" switch is what will "answer the phone" by lifting the receiver, and actually let you talk through your microphone if one is plugged in, as though you are making a mock phone call. Am I doing this right by incorporating both HTML and Javascript?
 
If an incoming call comes in, the app will make the phone ring. To take it off hook, lift the receiver by pressing Spacebar, which would otherwise trigger a "Pick Up Phone" noise (external), a "Telephone Connect Noise" (Internal", and a "Dial Tone" if no incoming call is present on the screen. This is loosely based on the phones of the web sites, TouchTone Telephone Emulator, Rotary Telephone Emulator, and Virtual Blue Box. Only this time, mine will be fully functional and accessible to screenreaders. What I want to do is create a Virtual Phone app for entertainment and fun, which can let you dial either Rotary pulses, DTMF Tones, MF Tones, or even SF Tones, and also have options for hearing payphone tones right from your computer. The "Hookswitch Status" switch is what will "answer the phone" by lifting the receiver, and actually let you talk through your microphone if one is plugged in, as though you are making a mock phone call. Am I doing this right by incorporating both HTML and Javascript?
There's nothing wrong with incorporating html and js... it's the norm by this point lol. The reason why I asked you to walk us through that snippet of code, was the fact that you have a function declared inside of another, and was wondering what the logic behind that was...also, this may be where you'll find the answer to your earlier question
1688885999651.png
 
There's nothing wrong with incorporating html and js... it's the norm by this point lol. The reason why I asked you to walk us through that snippet of code, was the fact that you have a function declared inside of another, and was wondering what the logic behind that was...also, this may be where you'll find the answer to your earlier question
View attachment 2195
Have you forgotten that I use a screenreader that can't recognize images? I'm sight challenged, specifically, I'm completely without sight, so I can't see them either.
 
There's nothing wrong with incorporating html and js... it's the norm by this point lol. The reason why I asked you to walk us through that snippet of code, was the fact that you have a function declared inside of another, and was wondering what the logic behind that was...also, this may be where you'll find the answer to your earlier question
View attachment 2195
Can you explain what you mean when you say, "a function declared inside of another"? How do I separate them?
 
Can you explain what you mean when you say, "a function declared inside of another"? How do I separate them?
JavaScript:
function incomingCall(){   //here is the start of the first function
    function ringTelephone(){    //here is the start of the second function
        if(!hasTelephoneBeenAnswered){
            ringRing.play();
            ringRing.currentTime=0;
        }
    }    //here is the end of the second function
    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}    //here is the end of the first function

See how ringTelephone is part of the body of incomingCall? I have a good idea of what you were aiming for: you wanted to call a function called ringTelephone() whenever the incomingCall function gets called. In order to resolve this and make it cleaner and clearer, you would have to place the ringTelephone function outside of the incomingCall function, and then inside of the incomingCall function, just place this ringTelephone(); as your first statement. See below:


JavaScript:
function ringTelephone(){
   //code for this function here
}

function incomingCall(){
    ringTelephone();

    if(isOffHook===false){
        ringRing.play();
        allowDial=false;
        callIncoming=true;
        setInterval(ringTelephone,5500);
    }
}
 
Have you forgotten that I use a screenreader that can't recognize images? I'm sight challenged, specifically, I'm completely without sight, so I can't see them either.
I do apologize...force of habit can be a bit of a bad call sometimes 🙂 , but what I was pointing to was your earlier comment about the error message you got, "expecting an else statement on Line 89:1"
 
I do apologize...force of habit can be a bit of a bad call sometimes 🙂 , but what I was pointing to was your earlier comment about the error message you got, "expecting an else statement on Line 89:1"
I copied your code exactly how you wrote it, via the "Copy To Clipboard" button, then pasted into my file. But I still don't know what I did wrong, as it still is giving me the "Keyword, Else" error. 1688932853798.png
 
Can you post what is on Line 96 of your file "virtual touch phone.html"?
This may be more than you asked for, but here goes:
JavaScript:
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();
 
Back
Top Bottom