<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Japanese Accent Ranker</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap');
/* Reset & base */
* {
box-sizing: border-box;
}
body, html {
margin: 0; padding: 0; height: 100%;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
font-family: 'Roboto Mono', monospace, monospace;
color: #ddd;
overflow: hidden;
}
/* Container */
#app {
max-width: 480px;
margin: 2rem auto;
background: rgba(30,30,30,0.65);
border-radius: 20px;
padding: 2rem 1.8rem 3rem 1.8rem;
box-shadow:
0 4px 15px rgba(255 255 255 / 0.1),
inset 0 0 60px 2px #1e90ff88,
0 0 40px 4px #1e90ff33;
backdrop-filter: blur(20px);
position: relative;
overflow: visible;
user-select: none;
}
/* Title */
h1 {
text-align: center;
font-weight: 700;
font-size: 2.4rem;
margin-bottom: 10px;
letter-spacing: 0.12em;
color: #50c0ff;
text-shadow:
0 0 6px #50c0ffaa,
0 0 15px #1e90ffcc;
}
/* Instructions */
#instructions {
color: #bbb;
font-size: 0.88rem;
text-align: center;
margin-bottom: 2rem;
line-height: 1.3;
opacity: 0.75;
user-select: text;
}
/* Mic Button */
#micBtn {
display: block;
margin: 0 auto 3rem auto;
background: transparent;
border: 2.8px solid #50c0ff88;
color: #50c0ffdd;
font-weight: 700;
font-size: 1.1rem;
padding: 0.7rem 2.8rem;
border-radius: 40px;
cursor: pointer;
position: relative;
overflow: hidden;
transition: all 0.35s ease-in-out;
box-shadow:
inset 0 0 15px #50c0ff44,
0 0 12px #50c0ff77;
user-select: none;
}
#micBtn:hover {
background: rgba(80,192,255,0.12);
border-color: #50c0ffcc;
box-shadow:
inset 0 0 40px #50c0ff88,
0 0 18px #50c0ffcc;
transform: scale(1.05);
}
#micBtn:active {
background: #50c0ff22;
box-shadow:
inset 0 0 55px #50c0ffaa,
0 0 22px #50c0ffaa;
transform: scale(0.95);
}
/* Animated mic waves */
#micBtn.recording {
border-color: #ff5e6dcc;
box-shadow:
0 0 30px #ff5e6dcc,
inset 0 0 45px #ff5e6dcc;
color: #ff5e6d;
animation: pulseBorder 2s infinite ease-in-out;
}
@keyframes pulseBorder {
0%, 100% {
box-shadow:
0 0 30px #ff5e6dcc,
inset 0 0 45px #ff5e6dcc;
border-color: #ff5e6dcc;
}
50% {
box-shadow:
0 0 60px #ff4970ff,
inset 0 0 70px #ff4970ff;
border-color: #ff4970ff;
}
}
/* Status message */
#status {
text-align: center;
color: #aaa;
font-size: 0.95rem;
min-height: 1.6rem;
margin-bottom: 2rem;
user-select: none;
filter: drop-shadow(0 0 2px #1e90ff33);
}
/* Result dial container */
#dialContainer {
position: relative;
margin: 0 auto;
width: 320px;
height: 320px;
border-radius: 50%;
background:
radial-gradient(circle at center, #0f314b 60%, #051622 98%);
box-shadow:
inset 0 0 30px 4px #1e90ff55,
0 0 18px #1e90ffaa;
user-select: none;
}
/* Dial: scale and center transform origin */
#dial {
position: absolute;
width: 280px;
height: 280px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-135deg);
border-radius: 50%;
background:
conic-gradient(
#1e90ff 0deg,
#50c0ff 162deg,
#1e90ff 270deg,
#0a1f34 270deg,
#0a1f34 390deg,
#1e90ff 390deg,
#50c0ff 405deg,
#1e90ff 495deg,
#0a1f34 495deg,
#0a1f34 495deg
);
box-shadow:
inset 0 0 20px #50c0ffaa,
0 0 22px #50c0ffcc;
filter: drop-shadow(0 0 4px #50c0ffbb);
}
/* The needle pivot circle center */
#needleBase {
position: absolute;
top: 50%;
left: 50%;
width: 32px; height: 32px;
background: linear-gradient(145deg, #121e31, #1a2c53);
border-radius: 50%;
border: 2.5px solid #50c0ffaa;
filter:
drop-shadow(0 0 4px #50c0ffdd);
transform: translate(-50%, -50%);
z-index: 10;
}
/* Needle */
#needle {
position: absolute;
bottom: 50%;
left: 50%;
width: 8px;
height: 130px;
background: linear-gradient(135deg, #ff5e6d, #ff2748);
border-radius: 4px 4px 0 0;
filter: drop-shadow(0 0 8px #ff5e6dcc);
transform-origin: 50% 100%;
transform: translateX(-50%) rotate(-135deg);
transition: transform 1.8s cubic-bezier(0.77,0,0.175,1);
box-shadow:
0 0 14px #ff4a5a,
inset 0 4px 8px #ff7085;
z-index: 12;
}
/* Needle glow */
#needleGlow {
position: absolute;
bottom: 50%;
left: 50%;
width: 22px;
height: 22px;
background: radial-gradient(circle, #ff5972 80%, transparent 102%);
filter: blur(6.4px);
border-radius: 50%;
transform: translate(-50%, 40%);
opacity: 0.7;
pointer-events: none;
z-index: 11;
}
/* Score text in center */
#scoreText {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -45%);
color: #ff4266;
font-weight: 900;
font-size: 5rem;
letter-spacing: 0.06em;
user-select: none;
filter:
drop-shadow(0 0 12px #ff4a6a85);
text-shadow:
0 0 8px #ff4a6aaa,
0 0 20px #ff4a6aff;
}
/* Score label in Japanese below */
#scoreLabel {
position: absolute;
top: 65%;
left: 50%;
transform: translateX(-50%);
font-weight: 700;
font-size: 1.5rem;
color: #50c0ffcc;
letter-spacing: 0.12em;
text-shadow: 0 0 8px #50c0ffcc;
user-select: none;
}
/* Microphone visualization waves */
#waveContainer {
position: absolute;
bottom: 3rem;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
justify-content: center;
align-items: center;
user-select: none;
}
.waveBar {
width: 8px;
background: linear-gradient(145deg, #0ff, #07eeff);
border-radius: 4px;
animation: waveAnim 1.2s infinite ease-in-out;
transform-origin: center bottom;
filter:
drop-shadow(0 0 5px #07eeffcc);
}
.waveBar:nth-child(1) { animation-delay: 0s; }
.waveBar:nth-child(2) { animation-delay: 0.2s; }
.waveBar:nth-child(3) { animation-delay: 0.4s; }
.waveBar:nth-child(4) { animation-delay: 0.6s; }
.waveBar:nth-child(5) { animation-delay: 0.8s; }
@keyframes waveAnim {
0%, 100% { height: 20px; opacity: 0.4;}
50% { height: 70px; opacity: 1;}
}
/* Tooltip style */
#micTooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%) translateY(-10px);
background: #050f14bb;
color: #c0eeffdd;
font-size: 0.75rem;
padding: 4px 12px;
border-radius: 14px;
pointer-events: none;
user-select: none;
opacity: 0;
transition: opacity 0.2s ease-in-out;
text-shadow: 0 0 3px #50c0ffbb;
letter-spacing: 0.08em;
font-weight: 600;
}
#micBtn[aria-describedby="micTooltip"]:hover + #micTooltip,
#micBtn:focus[aria-describedby="micTooltip"] + #micTooltip {
opacity: 1;
}
/* Scroll bar hidden */
::-webkit-scrollbar {
display: none;
}
/* Accessibility focus ring override */
#micBtn:focus-visible {
outline: 2.5px solid #50c0ffaa;
outline-offset: 5px;
}
</style>
</head>
<body>
<div id="app" role="main" aria-label="Japanese Accent ranker app">
<h1>Japanese Accent Ranker</h1>
<p id="instructions">
Click the microphone and say anything in Japanese.<br />
Your accent will be ranked 1〜100 based on pronunciation.
</p>
<button id="micBtn" aria-describedby="micTooltip" aria-pressed="false" aria-live="polite" aria-label="Start voice recognition">🎤 Start Listening</button>
<div id="micTooltip" role="tooltip">Click to start speaking Japanese</div>
<div id="status" aria-live="polite" aria-atomic="true">Idle</div>
<div id="dialContainer" aria-hidden="true">
<div id="dial"></div>
<div id="needleBase"></div>
<div id="needle"></div>
<div id="needleGlow"></div>
<div id="scoreText">--</div>
<div id="scoreLabel">アクセント</div>
</div>
<div id="waveContainer" aria-hidden="true" style="display:none;">
<div class="waveBar" style="animation-duration: 1.3s;"></div>
<div class="waveBar" style="animation-duration: 1.1s;"></div>
<div class="waveBar" style="animation-duration: 0.9s;"></div>
<div class="waveBar" style="animation-duration: 1.4s;"></div>
<div class="waveBar" style="animation-duration: 1s;"></div>
</div>
</div>
<script>
(() => {
'use strict';
// DOM elements
const micBtn = document.getElementById('micBtn');
const status = document.getElementById('status');
const needle = document.getElementById('needle');
const scoreText = document.getElementById('scoreText');
const waveContainer = document.getElementById('waveContainer');
// Needle rotation range:
// Min -135deg (score=0)
// Max 135deg (score=100)
const ANGLE_MIN = -135;
const ANGLE_MAX = 135;
let recognition;
let isListening = false;
// Accent scoring function (Mock implementation)
// In a real-world app, you'd call a pronunciation evaluation API.
// Here, we simulate scoring based on recognized words' confidence and Hiragana/Kanji presence.
// Since SpeechRecognition result doesn't contain accent per se, it's just a fun demo.
function computeAccentScore(transcript, confidence) {
// Basic heuristic scoring:
// - Higher confidence => higher score
// - Presence of Hiragana/Katakana/Kanji characters boosts score
// - Penalize if Latin characters detected
// - Slight randomness to simulate "accentness"
const jpChars = transcript.match(/[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF]/g) || [];
const latinChars = transcript.match(/[A-Za-z]/g) || [];
let baseScore = Math.round(confidence * 100);
if (jpChars.length === 0) {
// No Japanese chars = probably not Japanese => low score
return 5;
}
// Boost by how many Japanese chars (max 100)
const jpRatio = Math.min(jpChars.length / transcript.length, 1);
baseScore = baseScore * 0.8 + jpRatio * 40;
// Penalize if Latin characters present
if (latinChars.length > 0) {
baseScore -= latinChars.length * 4;
}
// Add a small randomness +/- 5
baseScore += (Math.random()*10-5);
// Clamp score 1 <= score <= 100
return Math.min(100, Math.max(1, Math.round(baseScore)));
}
// Smooth needle rotation to a target angle with animation
// Uses CSS transition on 'transform'
function setNeedleScore(score) {
// Map score 1-100 -> angle from ANGLE_MIN to ANGLE_MAX
const angle = ANGLE_MIN + (ANGLE_MAX - ANGLE_MIN) * (score/100);
// We rotate needle to angle
needle.style.transform = `translateX(-50%) rotate(${angle.toFixed(1)}deg)`;
// Update score text with Japanese label "アクセント"
scoreText.textContent = score.toString();
}
// Show status text with fade effect
function updateStatus(text, isError = false) {
status.textContent = text;
status.style.color = isError ? '#ff5e6d' : '#bbb';
}
// Start the speech recognition
function startRecognition() {
if (!recognition) {
updateStatus('Speech Recognition API not supported in your browser.', true);
return;
}
if (isListening) return;
recognition.lang = 'ja-JP';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.start();
isListening = true;
micBtn.textContent = '🎙️ Listening...';
micBtn.classList.add('recording');
micBtn.setAttribute('aria-pressed', 'true');
updateStatus('Please say something in Japanese...');
waveContainer.style.display = 'flex';
}
// Stop recognition
function stopRecognition() {
if (!recognition || !isListening) return;
recognition.stop();
isListening = false;
micBtn.textContent = '🎤 Start Listening';
micBtn.classList.remove('recording');
micBtn.setAttribute('aria-pressed', 'false');
updateStatus('Idle');
waveContainer.style.display = 'none';
}
// Initialize Web Speech API for recognition
function initRecognition() {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SpeechRecognition) {
updateStatus('Speech Recognition API not supported in your browser.', true);
micBtn.disabled = true;
return null;
}
const recog = new SpeechRecognition();
recog.addEventListener('start', () => {
updateStatus('Listening...');
micBtn.textContent = '🎙️ Listening...';
micBtn.classList.add('recording');
waveContainer.style.display = 'flex';
});
recog.addEventListener('end', () => {
// Automatically stop indicators if not listening flag (means we stopped)
if (isListening) {
// If ended unexpectedly, restart to allow continuous listening?
// We'll keep single shot only.
stopRecognition();
}
});
recog.addEventListener('error', e => {
let msg = '';
switch(e.error) {
case 'no-speech':
msg = 'No speech detected. Please try again.';
break;
case 'not-allowed':
msg = 'Permission to use microphone denied.';
micBtn.disabled = true;
break;
case 'audio-capture':
msg = 'No microphone found.';
micBtn.disabled = true;
break;
case 'aborted':
msg = 'Speech input aborted.';
break;
default:
msg = `Error occurred: ${e.error}`;
}
updateStatus(msg, true);
stopRecognition();
})
recog.addEventListener('result', e => {
if(!e.results || e.results.length === 0) {
updateStatus('No speech recognized. Try again.', true);
stopRecognition();
return;
}
let transcript = e.results[0][0].transcript.trim();
let confidence = e.results[0][0].confidence;
// Basic validation: ensure Japanese language used:
// if little/no Japanese chars => warning
let jpChars = transcript.match(/[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF]/g);
if(!jpChars || jpChars.length === 0) {
updateStatus('Detected non-Japanese or unclear speech. Please speak Japanese.', true);
setNeedleScore(1);
scoreText.textContent = '⚠️';
stopRecognition();
return;
}
// Compute accent score
const score = computeAccentScore(transcript, confidence);
updateStatus(`Recognized: "${transcript}" (confidence: ${(confidence*100).toFixed(0)}%)`);
setNeedleScore(score);
stopRecognition();
});
return recog;
}
// ### Initialization
recognition = initRecognition();
// Initial needle position
setNeedleScore(0);
// Button click handler toggle listen
micBtn.addEventListener('click', () => {
if (isListening) {
stopRecognition();
} else {
startRecognition();
}
});
// Keyboard accessibility: enter or space to toggle
micBtn.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
micBtn.click();
}
});
})();
</script>
</body>
</html>