Last active
April 3, 2024 20:16
-
-
Save bitmvr/840c6f97e0618128e59b6437768fc680 to your computer and use it in GitHub Desktop.
Mary Had A Little Lamb - DTMF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Navigate to http://onlinetonegenerator.com/dtmf.html | |
// Open DevTools - Console | |
// Paste the Code | |
// Press Enter | |
// Provide the number of milliseconds the default tone should hold for | |
var short = 250; | |
var long = short * 2; | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
var release = async function(duration){ | |
await sleep(duration); | |
stop(); | |
} | |
var tones = { | |
'0': [941.0, 1336.0], | |
'1': [697.0, 1209.0], | |
'2': [697.0, 1336.0], | |
'3': [697.0, 1477.0], | |
'4': [770.0, 1209.0], | |
'5': [770.0, 1336.0], | |
'6': [770.0, 1477.0], | |
'7': [852.0, 1209.0], | |
'8': [852.0, 1336.0], | |
'9': [852.0, 1477.0] | |
} | |
async function playTone(freq1, freq2, duration){ | |
dialTone(freq1, freq2); | |
await release(duration); | |
} | |
async function playSequence(){ | |
var sequence = [ | |
{ tone: '3', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '1', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '3', duration: long}, | |
{ tone: '2', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '2', duration: long}, | |
{ tone: '9', duration: short}, | |
{ tone: '9', duration: short}, | |
{ tone: '9', duration: long}, | |
{ tone: '3', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '1', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '3', duration: short}, | |
{ tone: '2', duration: short}, | |
{ tone: '1', duration: short} | |
]; | |
for (var { tone, duration } of sequence) { | |
var [freq1, freq2] = tones[tone]; | |
await playTone(freq1, freq2, duration); | |
} | |
} | |
playSequence(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment