Create single file HTML app, that allows the user to view an audiogram, drag its intensitied per ear, calculates SII with a BG noise slider and shows the speech sounds onthe audiogram. The speech sounds should dim based on their audibility relative to the hearing levels and the noise levels, to clearly show visually which sounds are clearly audible and which not.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is an example of a single‐file HTML “app” that puts an audiogram on a canvas, lets you drag threshold markers (separately for left‐ and right‑ears at fixed frequencies), includes a background‐noise slider, and plots several “speech sounds” (here labeled “m”, “a” and “s”) whose opacity is computed based on their level versus the average hearing threshold (plus noise) at that frequency. In this simplified example the Speech Intelligibility Index (SII) is computed as the weighted sum of “audibility factors” from each band. (In a clinical setting, the SII calculation is much more complex.)
Copy the code below into a file (for example, index.html) and open it in your browser.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Audiogram & SII Demo</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#controls {
margin-top: 10px;
}
#canvasContainer {
border: 1px solid #ccc;
display: inline-block;
}
.sliderLabel {
margin-right: 10px;
}
</style>
</head>
<body>
<h1>Audiogram & SII Demo</h1>
<div id="canvasContainer">
<canvas id="audiogramCanvas" width="700" height="450"></canvas>
</div>
<div id="controls">
<label class="sliderLabel" for="bgNoise">Background Noise (dB): </label>
<input type="range" id="bgNoise" min="0" max="60" step="1" value="0" />
<span id="bgNoiseValue">0</span>
<br />
<strong>SII:</strong> <span id="siiValue">0</span>
</div>
<script>
// ----- Configuration -----
// Frequencies (Hz) at which we display and edit thresholds.
const freqs = [250, 500, 1000, 2000, 4000, 8000];
// Initial thresholds (dB HL) for each ear (same length as freqs)
let leftEar = [10, 20, 30, 40, 50, 60];
let rightEar = [15, 25, 35, 45, 55, 65];
// Speech sounds (each with a label, center frequency, presentation level, and importance weight)
const speechSounds = [
{ label: "m", freq: 250, level: 55, importance: 0.3 },
{ label: "a", freq: 1000, level: 60, importance: 0.4 },
{ label: "s", freq: 6000, level: 65, importance: 0.3 },
];
// Canvas margins and dimensions for drawing
const canvas = document.getElementById("audiogramCanvas");
const ctx = canvas.getContext("2d");
const margin = { top: 50, right: 50, bottom: 50, left: 60 };
const drawWidth = canvas.width - margin.left - margin.right;
const drawHeight = canvas.height - margin.top - margin.bottom;
const minDB = 0;
const maxDB = 100;
const pointRadius = 8; // for draggable markers
// Select slider element
const bgNoiseSlider = document.getElementById("bgNoise");
const bgNoiseDisplay = document.getElementById("bgNoiseValue");
const siiDisplay = document.getElementById("siiValue");
// Hold state for dragging
let dragging = null; // { ear: "left"|"right", index: number }
let offsetY = 0;
// Conversion functions
function xForFreq(i) {
// spacing markers evenly over the x-range.
return margin.left + (i / (freqs.length - 1)) * drawWidth;
}
function yForDB(db) {
// Map dB (minDB at top, maxDB at bottom)
const fraction = (db - minDB) / (maxDB - minDB);
return margin.top + fraction * drawHeight;
}
function dbForY(y) {
const fraction = (y - margin.top) / drawHeight;
return fraction * (maxDB - minDB) + minDB;
}
// Linear interpolation for thresholds at arbitrary frequency from the six markers.
// Here we assume freqs array is sorted ascending.
function interpThreshold(thresholds, freq) {
if (freq <= freqs[0]) return thresholds[0];
if (freq >= freqs[freqs.length - 1]) return thresholds[thresholds.length - 1];
for (let i = 0; i < freqs.length - 1; i++) {
if (freq >= freqs[i] && freq <= freqs[i + 1]) {
const t = (freq - freqs[i]) / (freqs[i + 1] - freqs[i]);
return thresholds[i] + t * (thresholds[i + 1] - thresholds[i]);
}
}
return thresholds[thresholds.length - 1];
}
// Calculate the overall SII (a simple weighted sum of audibility in three bands)
function calculateSII(bgNoise) {
let total = 0;
let weightTotal = 0;
speechSounds.forEach(sound => {
// Average threshold from both ears at this sound frequency.
const threshLeft = interpThreshold(leftEar, sound.freq);
const threshRight = interpThreshold(rightEar, sound.freq);
const avgThresh = (threshLeft + threshRight) / 2;
// Consider bgNoise shifts the effective threshold.
const effectiveThresh = avgThresh + bgNoise;
let diff = sound.level - effectiveThresh; // dB difference
// We use a criterion: fully audible if diff >= 0; inaudible if diff <= -20.
let audibility = 0;
if (diff >= 0) {
audibility = 1;
} else if (diff <= -20) {
audibility = 0;
} else {
audibility = (diff + 20) / 20;
}
total += sound.importance * audibility;
weightTotal += sound.importance;
});
// SII percentage (0-100)
return Math.round((total / weightTotal) * 100);
}
// Draw the audiogram, markers, curves, speech sounds and update SII
function drawAudiogram() {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw grid (frequency vs dB)
ctx.strokeStyle = "#ddd";
ctx.lineWidth = 1;
// horizontal lines every 10 dB
for (let db = minDB; db <= maxDB; db += 10) {
const y = yForDB(db);
ctx.beginPath();
ctx.moveTo(margin.left, y);
ctx.lineTo(canvas.width - margin.right, y);
ctx.stroke();
ctx.fillStyle = "#777";
ctx.font = "12px Arial";
ctx.fillText(db + " dB", 5, y + 4);
}
// vertical lines at each fixed frequency marker
for (let i = 0; i < freqs.length; i++) {
const x = xForFreq(i);
ctx.beginPath();
ctx.moveTo(x, margin.top);
ctx.lineTo(x, canvas.height - margin.bottom);
ctx.stroke();
ctx.fillStyle = "#777";
ctx.font = "12px Arial";
ctx.textAlign = "center";
ctx.fillText(freqs[i] + " Hz", x, canvas.height - margin.bottom + 15);
}
// Draw title labels for ears
ctx.fillStyle = "blue";
ctx.fillText("Left Ear", margin.left, margin.top - 20);
ctx.fillStyle = "red";
ctx.fillText("Right Ear", margin.left + drawWidth - 50, margin.top - 20);
// Draw curves for left and right ear thresholds
function drawCurve(thresholds, color) {
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.beginPath();
for (let i = 0; i < thresholds.length; i++) {
const x = xForFreq(i);
const y = yForDB(thresholds[i]);
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.stroke();
}
drawCurve(leftEar, "blue");
drawCurve(rightEar, "red");
// Draw draggable points as circles
function drawPoints(thresholds, color) {
for (let i = 0; i < thresholds.length; i++) {
const x = xForFreq(i);
const y = yForDB(thresholds[i]);
ctx.beginPath();
ctx.arc(x, y, pointRadius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
ctx.strokeStyle = "#333";
ctx.stroke();
}
}
drawPoints(leftEar, "blue");
drawPoints(rightEar, "red");
// Get current background noise value from slider.
const bgNoise = parseFloat(bgNoiseSlider.value);
// Draw speech sounds markers (adjust opacity based on audibility)
speechSounds.forEach(sound => {
// Compute average threshold using linear interpolation
const threshLeft = interpThreshold(leftEar, sound.freq);
const threshRight = interpThreshold(rightEar, sound.freq);
const avgThresh = (threshLeft + threshRight) / 2;
const effectiveThresh = avgThresh + bgNoise;
let diff = sound.level - effectiveThresh;
let audibility = 0; // from 0 (inaudible) to 1 (fully audible)
if (diff >= 0) {
audibility = 1;
} else if (diff <= -20) {
audibility = 0;
} else {
audibility = (diff + 20) / 20;
}
// Map sound level to canvas y coordinate
const x = margin.left + drawWidth * ((Math.log(sound.freq) - Math.log(freqs[0])) / (Math.log(freqs[freqs.length - 1]) - Math.log(freqs[0])));
const y = yForDB(sound.level);
// Draw a circle with opacity based on audibility
ctx.beginPath();
ctx.arc(x, y, 15, 0, Math.PI * 2);
ctx.fillStyle = `rgba(0, 150, 0, ${0.3 + 0.7 * audibility})`;
ctx.fill();
// Draw label in the center
ctx.fillStyle = "white";
ctx.font = "bold 16px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(sound.label, x, y);
});
// Update SII value
const sii = calculateSII(bgNoise);
siiDisplay.textContent = sii;
}
// --- Mouse events for dragging markers ---
canvas.addEventListener("mousedown", event => {
const rect = canvas.getBoundingClientRect();
const mouseX = event.clientX - rect.left;
const mouseY = event.clientY - rect.top;
// Check both ears' markers.
// Priority: left ear then right ear.
for (let earName of ["left", "right"]) {
const markers = earName === "left" ? leftEar : rightEar;
for (let i = 0; i < markers.length; i++) {
const x = xForFreq(i);
const y = yForDB(markers[i]);
const dx = mouseX - x;
const dy = mouseY - y;
if (Math.sqrt(dx * dx + dy * dy) < pointRadius + 3) {
dragging = { ear: earName, index: i };
offsetY = dy;
return;
}
}
}
});
canvas.addEventListener("mousemove", event => {
if (!dragging) return;
const rect = canvas.getBoundingClientRect();
const mouseY = event.clientY - rect.top;
// Compute new dB value from mouseY
let newDB = dbForY(mouseY - offsetY);
// Constrain to min and max
newDB = Math.max(minDB, Math.min(maxDB, newDB));
if (dragging.ear === "left") {
leftEar[dragging.index] = newDB;
} else {
rightEar[dragging.index] = newDB;
}
drawAudiogram();
});
canvas.addEventListener("mouseup", () => {
dragging = null;
});
canvas.addEventListener("mouseleave", () => {
dragging = null;
});
// Update when background noise slider changes
bgNoiseSlider.addEventListener("input", () => {
bgNoiseDisplay.textContent = bgNoiseSlider.value;
drawAudiogram();
});
// Initial draw
drawAudiogram();
</script>
</body>
</html>
How It Works
Audiogram Grid & Markers:
The canvas displays a grid with horizontal lines for dB (0–100) and vertical lines for preset frequencies (250, 500, 1000, 2000, 4000, 8000 Hz).
There are two sets of draggable markers: blue for the left ear and red for the right ear. You can drag a marker vertically (the x‐position stays fixed) to change the hearing threshold at that frequency.
Speech Sounds & Audibility:
Three speech sounds (“m”, “a”, “s”) are drawn as green circles whose opacity depends on how far above the effective threshold (average of left/right at that frequency plus background noise) the sound’s presentation level is.
A simple linear mapping sets the “audibility” (and thus the opacity) so that if the sound level is 20 dB below the effective threshold it is completely “dim” (inaudible) and if it is at or above threshold it appears fully visible.
Background Noise & SII:
A slider labeled “Background Noise” lets you add a noise level that effectively raises the hearing thresholds.
The app computes a simplified SII value (as a weighted average of audibility across speech sounds) and displays it below the slider.
This complete HTML file is self-contained; simply open it in a modern browser to experiment with auditory curves and SII visualization.