← 返回首页/ 🈵 汉字转拼音工具

汉字转拼音

带声调/无声调 · 多格式输出 · 批量处理 · 支持姓名拼音

📢 广告位 · 起名服务 / 教育类合作欢迎联系
⚙️ 转换选项
声调显示
输出格式
📝 输入汉字
📚 声母韵母速查
声母(21个)
{b p m f d t n l g k h j q x zh ch sh r z c s y w} .replace(/{(.+)}/,'$1').trim().split(' ').map(s=>`${s}`).join('')
常见多音字
de / dí / dì / dī
dì / de
dé / de / děi
cháng / zhǎng
xíng / háng
zhōng / zhòng
zhòng / chóng
hǎo / hào
乐 document.getElementById('opt-tone'+(t==='tone'?1:t==='notone'?2:3)).classList.toggle('active',t===m)); } function setFmt(m) { fmtMode = m; ['space','above','inline','first'].forEach((t,i) => document.getElementById(['fmt-space','fmt-above','fmt-inline','fmt-first'][i]).classList.toggle('active',t===m)); } function convTone(pinyin) { if (toneMode==='tone') return pinyin; if (toneMode==='notone') return pinyin.split('').map(c=>NOTONE_MAP[c]||c).join(''); if (toneMode==='num') { let tone = 0; const base = pinyin.split('').map(c=>{ const t=TONES[c]; if(t&&/\d/.test(t.slice(-1))){ tone=t.slice(-1); return t.slice(0,-1); } return NOTONE_MAP[c]||c; }).join(''); return base + (tone||''); } return pinyin; } function getCharPinyin(char) { return PINYIN_MAP[char] || null; } function convertPinyin() { const text = document.getElementById('input-text').value; if (!text.trim()) { alert('请输入汉字'); return; } const chars = text.split(''); const pairs = chars.map(c => { const py = getCharPinyin(c); return { char:c, pinyin: py ? convTone(py) : null }; }); // Display result let displayHTML = ''; let textResult = ''; if (fmtMode === 'above') { displayHTML = '
'; pairs.forEach(p => { if (p.pinyin) { displayHTML += `${p.pinyin}
${p.char}
`; textResult += p.pinyin + ' '; } else if (p.char === '\n') { displayHTML += '
'; textResult += '\n'; } else { displayHTML += `-
${p.char}
`; textResult += p.char; } }); displayHTML += '
'; } else if (fmtMode === 'inline') { pairs.forEach(p => { if (p.pinyin) { textResult += `${p.char}(${p.pinyin})`; } else { textResult += p.char; } }); displayHTML = `
${textResult.replace(/\n/g,'
')}
`; } else if (fmtMode === 'first') { pairs.forEach(p => { if (p.pinyin) { textResult += p.pinyin[0].toUpperCase(); } else if (p.char === '\n') { textResult += '\n'; } else { textResult += p.char; } }); displayHTML = `
${textResult}
`; } else { // space pairs.forEach(p => { if (p.pinyin) { textResult += p.pinyin + ' '; } else if (p.char === '\n') { textResult = textResult.trim() + '\n'; } else { textResult += p.char; } }); displayHTML = `
${textResult.replace(/\n/g,'
')}
`; } document.getElementById('display-result').innerHTML = displayHTML; document.getElementById('text-result').value = textResult.trim(); document.getElementById('result-area').style.display='block'; saveHistory(text.slice(0,30)); } function copyResult() { navigator.clipboard.writeText(document.getElementById('text-result').value).then(()=>alert('✅ 已复制')); } function clearAll() { document.getElementById('input-text').value=''; document.getElementById('result-area').style.display='none'; } function saveHistory(preview) { let h = JSON.parse(localStorage.getItem('pinyin_history')||'[]'); h.unshift({preview, date:new Date().toLocaleDateString('zh-CN')}); if(h.length>5) h=h.slice(0,5); localStorage.setItem('pinyin_history', JSON.stringify(h)); } // Render initials reference document.querySelector('.options-row').insertAdjacentHTML('afterend',''); // Fix the template literal in HTML document.querySelectorAll('.card-title')[1].parentElement.querySelector('div:last-child div').innerHTML = 'b p m f d t n l g k h j q x zh ch sh r z c s y w'.split(' ').map(s=>`${s}`).join('');