By Using Video to Audio Converter tool you can convert your video into audio file and can download in mp3 format. bolow it the free complete tested code.
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Video to Audio Converter</title><style>body {font-family: Arial, sans-serif;background: linear-gradient(135deg, #ff7eb3, #ff758c);color: #fff;margin: 0;padding: 0;display: flex;justify-content: center;align-items: center;height: 100vh;}.container {text-align: center;background: rgba(0, 0, 0, 0.7);padding: 20px;border-radius: 10px;box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);}h1 {font-size: 2rem;margin-bottom: 20px;}input[type="file"] {margin-bottom: 20px;padding: 10px;border: none;border-radius: 5px;cursor: pointer;background-color: #ff5757;color: white;}input[type="file"]:hover {background-color: #ff4343;}button {padding: 10px 20px;border: none;border-radius: 5px;cursor: pointer;background-color: #4caf50;color: white;font-size: 1rem;}button:hover {background-color: #45a049;}.output {margin-top: 20px;}.output a {color: #4caf50;text-decoration: none;font-weight: bold;}.output a:hover {text-decoration: underline;}</style></head><body><div class="container"><h1>Video to Audio Converter</h1><input type="file" id="videoInput" accept="video/*"><br><button id="convertButton">Convert to Audio</button><div class="output" id="output"></div></div><script>document.getElementById('convertButton').addEventListener('click', () => {const videoInput = document.getElementById('videoInput');const outputDiv = document.getElementById('output');if (!videoInput.files.length) {alert('Please select a video file first.');return;}const videoFile = videoInput.files[0];const audioContext = new (window.AudioContext || window.webkitAudioContext)();const reader = new FileReader();reader.onload = async (event) => {const arrayBuffer = event.target.result;const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);const offlineContext = new OfflineAudioContext(audioBuffer.numberOfChannels,audioBuffer.length,audioBuffer.sampleRate);const source = offlineContext.createBufferSource();source.buffer = audioBuffer;source.connect(offlineContext.destination);source.start();offlineContext.startRendering().then((renderedBuffer) => {const blob = new Blob([new DataView(renderedBuffer)], { type: 'audio/mpeg' });const url = URL.createObjectURL(blob);outputDiv.innerHTML = `<a href="${url}" download="audio.mp3">Download Audio</a>`;});};reader.readAsArrayBuffer(videoFile);});</script></body></html>
Tags:
Free Tools