Download index.html from PacketExchange/dtmf-tone-generator: direct link, hf CLI and curl.
- Browser
- Download file 11.1 kB
-
https://huggingface.co/spaces/PacketExchange/dtmf-tone-generator/resolve/main/index.html
- Command line
-
hf download hf://spaces/PacketExchange/dtmf-tone-generator/index.html
-
curl -L -o index.html https://huggingface.co/spaces/PacketExchange/dtmf-tone-generator/resolve/main/index.html
11.1 kB
| <html lang="en-GB"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>DTMF Tone Generator</title> | |
| <style> | |
| :root{--bg:#0A0E14;--panel:#111722;--line:#1E2938;--ink:#E8EDF5;--muted:#93A1B5;--brass:#E8C87E;--brass-dim:#C9A85C;--bad:#F08A7E;--ok:#8FD3A5} | |
| *{box-sizing:border-box} | |
| body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;padding:32px 16px 64px} | |
| .wrap{max-width:860px;margin:0 auto} | |
| .top{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:22px;font-size:13px;color:var(--muted)} | |
| .top a{color:var(--brass);text-decoration:none} | |
| h1{font-size:26px;margin:0 0 6px;letter-spacing:-0.01em} | |
| h2{font-size:15px;margin:0 0 14px;color:var(--brass);text-transform:uppercase;letter-spacing:.08em} | |
| p{color:var(--muted);margin:0 0 14px} | |
| .lede{color:var(--ink);font-size:16px} | |
| .card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:20px;margin:18px 0} | |
| .row{display:flex;flex-wrap:wrap;gap:12px;align-items:center} | |
| .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px} | |
| button{background:var(--brass);color:#14100A;border:0;border-radius:8px;padding:10px 16px;font-weight:600;font-size:14px;cursor:pointer} | |
| button.ghost{background:transparent;color:var(--brass);border:1px solid var(--brass-dim)} | |
| button:disabled{opacity:.45;cursor:not-allowed} | |
| label{display:block;font-size:13px;color:var(--muted);margin-bottom:6px} | |
| select,input[type=text],textarea{background:#0C121C;color:var(--ink);border:1px solid var(--line);border-radius:8px;padding:9px 10px;font-size:14px;width:100%} | |
| textarea{min-height:120px;resize:vertical;font-family:inherit} | |
| input[type=range]{width:100%;accent-color:var(--brass)} | |
| .val{color:var(--brass);font-variant-numeric:tabular-nums} | |
| .stat{background:#0C121C;border:1px solid var(--line);border-radius:10px;padding:12px 14px} | |
| .stat .k{font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em} | |
| .stat .v{font-size:22px;font-weight:600;color:var(--ink);font-variant-numeric:tabular-nums} | |
| .stat .v.bad{color:var(--bad)} .stat .v.ok{color:var(--ok)} | |
| .note{font-size:13px;color:var(--muted)} | |
| .bullets{color:var(--muted);padding-left:18px;margin:0 0 6px} | |
| .bullets li{margin-bottom:8px} | |
| a{color:var(--brass)} | |
| footer{margin-top:28px;font-size:13px;color:var(--muted)} | |
| code,.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px} | |
| .pill{display:inline-block;padding:2px 8px;border-radius:999px;border:1px solid var(--line);font-size:12px;color:var(--muted);margin:2px 4px 2px 0} | |
| table{width:100%;border-collapse:collapse;font-size:14px} | |
| th,td{text-align:left;padding:8px 6px;border-bottom:1px solid var(--line)} | |
| th{color:var(--muted);font-weight:500;font-size:12px;text-transform:uppercase;letter-spacing:.06em} | |
| .pad{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;max-width:360px} | |
| .pad button{background:#0C121C;color:var(--ink);border:1px solid var(--line);font-size:18px;padding:14px 0} | |
| .pad button:active{background:var(--brass);color:#14100A} | |
| .pad button span{display:block;font-size:10px;color:var(--muted);letter-spacing:.1em} | |
| .seq{font-size:28px;letter-spacing:.12em;min-height:44px;font-variant-numeric:tabular-nums} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="wrap"> | |
| <div class="top"> | |
| <span>PacketExchange developer tools</span> | |
| <a href="https://huggingface.co/PacketExchange">More tools</a> | |
| </div> | |
| <h1>DTMF Tone Generator</h1> | |
| <p class="lede">Generate exact keypad tones to test an IVR, a voice agent that collects digits, or a DTMF detector, and download them as a telephony wav.</p> | |
| <p>Each key is two sine waves from the ITU-T Q.23 table, mixed at equal level. Playback and the download are made in your browser.</p> | |
| <div class="card"> | |
| <h2>Sequence</h2> | |
| <div class="grid"> | |
| <div> | |
| <div class="pad" id="pad"></div> | |
| </div> | |
| <div> | |
| <label for="seqIn">Or type it (0-9, *, #, A-D, comma for a pause)</label> | |
| <input type="text" id="seqIn" placeholder="1,,482913#" class="mono"> | |
| <div class="seq mono" id="seq"></div> | |
| <div class="grid" style="margin-top:10px"> | |
| <div><label for="tone">Tone length <span class="val" id="toneVal">100 ms</span></label><input type="range" id="tone" min="40" max="500" step="10" value="100"></div> | |
| <div><label for="gap">Gap <span class="val" id="gapVal">100 ms</span></label><input type="range" id="gap" min="40" max="500" step="10" value="100"></div> | |
| <div><label for="rate">Sample rate</label><select id="rate"><option value="8000">8 kHz (telephony)</option><option value="16000">16 kHz</option><option value="44100">44.1 kHz</option></select></div> | |
| </div> | |
| <div class="row" style="margin-top:14px"> | |
| <button id="play">Play</button> | |
| <button id="dl" class="ghost">Download wav</button> | |
| <button id="clear" class="ghost">Clear</button> | |
| </div> | |
| </div> | |
| </div> | |
| <p class="note" style="margin-top:12px">A comma inserts a one second pause, the same convention as a dial string. Minimum tone and gap for most detectors is 40 ms, and 70 to 100 ms is the safe range when you are driving someone else's IVR.</p> | |
| </div> | |
| <div class="card"> | |
| <h2>Frequency table</h2> | |
| <table> | |
| <thead><tr><th></th><th>1209 Hz</th><th>1336 Hz</th><th>1477 Hz</th><th>1633 Hz</th></tr></thead> | |
| <tbody> | |
| <tr><th>697 Hz</th><td>1</td><td>2</td><td>3</td><td>A</td></tr> | |
| <tr><th>770 Hz</th><td>4</td><td>5</td><td>6</td><td>B</td></tr> | |
| <tr><th>852 Hz</th><td>7</td><td>8</td><td>9</td><td>C</td></tr> | |
| <tr><th>941 Hz</th><td>*</td><td>0</td><td>#</td><td>D</td></tr> | |
| </tbody> | |
| </table> | |
| <ul class="bullets" style="margin-top:14px"> | |
| <li>On a real call, digits are often carried out of band as RFC 4733 telephone events rather than as audio. If your agent only listens for tones in the audio it will miss them on many routes, and if it only reads events it will miss them on others. Handle both.</li> | |
| <li>Compressed codecs can mangle in-band tones. G.711 passes them cleanly, which is one reason IVRs still live on it.</li> | |
| <li>A, B, C and D exist on the keypad standard but on almost no handsets. Useful for testing that a detector ignores what it should.</li> | |
| </ul> | |
| </div> | |
| <footer> | |
| Built by <a href="https://huggingface.co/PacketExchange">PacketExchange</a>. The <a href="https://packetexchange.io/developers">PacketExchange API</a> can place a call, speak text, play audio and collect keypad input in one request, so an agent can be tested end to end on a real number. | |
| Questions are welcome at <a href="mailto:contact@packetexchange.io">contact@packetexchange.io</a>. | |
| </footer> | |
| </div> | |
| <script> | |
| (function(){ | |
| "use strict"; | |
| var LOW = {"1":697,"2":697,"3":697,"A":697,"4":770,"5":770,"6":770,"B":770,"7":852,"8":852,"9":852,"C":852,"*":941,"0":941,"#":941,"D":941}; | |
| var HIGH = {"1":1209,"4":1209,"7":1209,"*":1209,"2":1336,"5":1336,"8":1336,"0":1336,"3":1477,"6":1477,"9":1477,"#":1477,"A":1633,"B":1633,"C":1633,"D":1633}; | |
| var KEYS = ["1","2","3","A","4","5","6","B","7","8","9","C","*","0","#","D"]; | |
| var els = { pad: document.getElementById('pad'), seqIn: document.getElementById('seqIn'), seq: document.getElementById('seq'), tone: document.getElementById('tone'), gap: document.getElementById('gap'), toneVal: document.getElementById('toneVal'), gapVal: document.getElementById('gapVal'), rate: document.getElementById('rate'), play: document.getElementById('play'), dl: document.getElementById('dl'), clear: document.getElementById('clear') }; | |
| var AC = window.AudioContext || window.webkitAudioContext, ctx = null; | |
| function actx(){ if(!ctx) ctx = new AC(); if(ctx.state === 'suspended') ctx.resume(); return ctx; } | |
| KEYS.forEach(function(k){ | |
| var b = document.createElement('button'); b.innerHTML = k + '<span>' + LOW[k] + '+' + HIGH[k] + '</span>'; | |
| b.addEventListener('click', function(){ els.seqIn.value += k; beep(k); render(); }); | |
| els.pad.appendChild(b); | |
| }); | |
| function clean(){ return els.seqIn.value.toUpperCase().replace(/[^0-9A-D*#,]/g, ""); } | |
| function render(){ els.seq.textContent = clean(); } | |
| els.seqIn.addEventListener('input', render); | |
| els.tone.addEventListener('input', function(){ els.toneVal.textContent = els.tone.value + ' ms'; }); | |
| els.gap.addEventListener('input', function(){ els.gapVal.textContent = els.gap.value + ' ms'; }); | |
| els.clear.addEventListener('click', function(){ els.seqIn.value = ""; render(); }); | |
| function beep(k){ | |
| var c = actx(), t = c.currentTime, dur = parseInt(els.tone.value, 10) / 1000; | |
| [LOW[k], HIGH[k]].forEach(function(f){ | |
| var o = c.createOscillator(), g = c.createGain(); | |
| o.frequency.value = f; g.gain.value = 0.25; o.connect(g); g.connect(c.destination); o.start(t); o.stop(t + dur); | |
| }); | |
| } | |
| function synth(rate){ | |
| var toneMs = parseInt(els.tone.value, 10), gapMs = parseInt(els.gap.value, 10), s = clean(); | |
| var toneN = Math.round(rate * toneMs / 1000), gapN = Math.round(rate * gapMs / 1000), pauseN = rate; | |
| var total = 0, i; | |
| for(i = 0; i < s.length; i++) total += (s[i] === ',') ? pauseN : (toneN + gapN); | |
| var out = new Float32Array(Math.max(total, 1)), pos = 0, ramp = Math.round(rate * 0.005); | |
| for(i = 0; i < s.length; i++){ | |
| var k = s[i]; | |
| if(k === ','){ pos += pauseN; continue; } | |
| for(var n = 0; n < toneN; n++){ | |
| var env = Math.min(1, n / ramp, (toneN - n) / ramp); | |
| out[pos + n] = 0.45 * env * (Math.sin(2 * Math.PI * LOW[k] * n / rate) + Math.sin(2 * Math.PI * HIGH[k] * n / rate)) / 2; | |
| } | |
| pos += toneN + gapN; | |
| } | |
| return out; | |
| } | |
| els.play.addEventListener('click', function(){ | |
| var c = actx(), rate = c.sampleRate, data = synth(rate); | |
| var buf = c.createBuffer(1, data.length, rate); buf.getChannelData(0).set(data); | |
| var src = c.createBufferSource(); src.buffer = buf; src.connect(c.destination); src.start(); | |
| }); | |
| els.dl.addEventListener('click', function(){ | |
| var rate = parseInt(els.rate.value, 10), data = synth(rate), bytes = data.length * 2; | |
| var ab = new ArrayBuffer(44 + bytes), v = new DataView(ab), o = 0; | |
| function str(x){ for(var i = 0; i < x.length; i++) v.setUint8(o++, x.charCodeAt(i)); } | |
| function u32(x){ v.setUint32(o, x, true); o += 4; } function u16(x){ v.setUint16(o, x, true); o += 2; } | |
| str('RIFF'); u32(36 + bytes); str('WAVE'); str('fmt '); u32(16); u16(1); u16(1); u32(rate); u32(rate * 2); u16(2); u16(16); str('data'); u32(bytes); | |
| for(var i = 0; i < data.length; i++){ var x = Math.max(-1, Math.min(1, data[i])); v.setInt16(44 + i * 2, x < 0 ? x * 32768 : x * 32767, true); } | |
| var a = document.createElement('a'); a.href = URL.createObjectURL(new Blob([ab], {type: 'audio/wav'})); a.download = 'dtmf-' + (clean().replace(/[^0-9A-D]/g, '') || 'tones') + '.wav'; a.click(); | |
| }); | |
| render(); | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |