<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>普通话学习助手</title>
    <!-- 引入字体 -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&display=swap" rel="stylesheet">
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', Arial, sans-serif;
            background: linear-gradient(135deg, #f0f4f8 0%, #d9e8ff 100%);
            color: #333;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        .container {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
        }

        .content {
            background-color: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(5px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            padding: 40px;
            border-radius: 16px;
            text-align: center;
            max-width: 600px;
            width: 100%;
            animation: fadeIn 1s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        h1 {
            color: #1e88e5;
            font-size: 2.5em;
            margin-bottom: 30px;
        }

        button {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 15px 30px;
            font-size: 1.1em;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            margin-bottom: 20px;
        }

        button::after {
            content: '';
            position: absolute;
            left: -10%;
            top: -50%;
            width: 120%;
            height: 200%;
            background: rgba(255, 255, 255, 0.3);
            transform: rotate(45deg);
            opacity: 0;
            transition: all 0.5s ease;
        }

        button:hover {
            background-color: #1565c0;
        }

        button:hover::after {
            top: -20%;
            opacity: 1;
        }

        #result {
            margin-top: 20px;
        }

        .result-block {
            padding: 20px;
            border-radius: 16px;
            background-color: rgba(250, 250, 250, 0.9);
            box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.05);
            text-align: left;
            margin-bottom: 20px;
        }

        .result-block h2 {
            font-size: 1.5em;
            color: #1e88e5;
            margin-bottom: 15px;
        }

        .result-block p {
            font-size: 1.2em;
            color: #333;
            line-height: 1.6;
            margin-bottom: 10px;
        }

        audio {
            margin-top: 10px;
            width: 100%;
            outline: none;
        }

        /* 作者信息 */
        .footer {
            text-align: center;
            padding: 20px;
            font-size: 1em;
            color: #888;
        }

        .footer a {
            color: #1e88e5;
            text-decoration: none;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            h1 {
                font-size: 2em;
            }

            button {
                padding: 12px 24px;
                font-size: 1em;
            }

            .result-block h2 {
                font-size: 1.3em;
            }

            .result-block p {
                font-size: 1em;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="content">
            <h1>普通话学习助手</h1>
            <button id="recordButton">开始录音</button>
            <div id="result"></div>
        </div>
    </div>

    <!-- 作者信息 -->
    <div class="footer">
        © 2024 <a href="#">hooxing</a>
    </div>

    <script>
        const recordButton = document.getElementById('recordButton');
        const resultDiv = document.getElementById('result');
        let mediaRecorder;
        let audioChunks = [];

        recordButton.addEventListener('click', async () => {
            if (recordButton.textContent === '开始录音') {
                await startRecording();
                recordButton.textContent = '停止录音';
            } else {
                stopRecording();
                recordButton.textContent = '开始录音';
            }
        });

        async function startRecording() {
            const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
            mediaRecorder = new MediaRecorder(stream, {
                mimeType: 'audio/webm;codecs=opus',
                audioBitsPerSecond: 16000
            });
            mediaRecorder.ondataavailable = event => {
                audioChunks.push(event.data);
            };
            mediaRecorder.onstop = async () => {
                const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
                audioChunks = [];
                const formData = new FormData();
                formData.append('audio', audioBlob, 'recording.webm');

                try {
                    const response = await fetch('http://127.0.0.1:5000/getJson', {
                        method: 'POST',
                        body: formData
                    });
                    const result = await response.json();
                    displayResult(result);
                } catch (error) {
                    console.error('Error:', error);
                    alert('处理录音时出错，请重试。');
                }
            };
            mediaRecorder.start();
        }

        function stopRecording() {
            mediaRecorder.stop();
        }

        function displayResult(result) {
            resultDiv.innerHTML = `
                <div class="result-block">
                    <h2>识别结果</h2>
                    <p><strong>文本：</strong>${result.text}</p>
                    <p><strong>拼音：</strong>${result.pinyin.join(', ')}</p>
                    <audio controls src="${result.speech_url}"></audio>
                </div>
                <div class="result-block">
                    <h2>修正建议</h2>
                    <p>${result.suggestions}</p>
                </div>
            `;
        }
    </script>
</body>
</html>
----------
优化此页面，当录音结束后等待接口返回时不可点击按钮，提升用户正在处理中。在页面中添加一些提示，这个工具是通过一段录音来分析普通话中的错误，结果仅供参考。还要加一个提示，可以让用户照着读的几句话