index.html

 avatar
lalisadnn
plain_text
25 days ago
1.6 kB
2
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Voice Transcription</title>
</head>
<body>
    <h1>Voice Transcription</h1>
    <button onclick="startRecording()">Start Recording</button>
    <button onclick="stopRecording()">Stop Recording</button>
    <p id="transcript"></p>

    <script>
        let mediaRecorder;
        let audioChunks = [];

        function startRecording() {
            navigator.mediaDevices.getUserMedia({ audio: true })
                .then(stream => {
                    mediaRecorder = new MediaRecorder(stream);
                    mediaRecorder.start();
                    mediaRecorder.ondataavailable = event => {
                        audioChunks.push(event.data);
                    };
                });
        }

        function stopRecording() {
            mediaRecorder.stop();
            mediaRecorder.onstop = () => {
                const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
                const audioUrl = URL.createObjectURL(audioBlob);
                audioChunks = [];

                // Send audio to server
                const formData = new FormData();
                formData.append('audio', audioBlob, 'audio.wav');

                fetch('/transcribe', {
                    method: 'POST',
                    body: formData
                })
                .then(response => response.json())
                .then(data => {
                    document.getElementById('transcript').innerText = data.transcript;
                });
            };
        }
    </script>
</body>
</html>
Leave a Comment