const htmlContent =`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Speech-to-Text</title></head><body><input type="file" id="audioFileInput" accept=".mp3, .wav"><script src="your_script.js"></script></body></html>`;// Create a new document and set its content to the HTMLconst newDocument =newDOMParser().parseFromString(htmlContent,'text/html');// Append the new document's body to the current document's body
document.body.appendChild(newDocument.body);// Replace 'YOUR_API_KEY' with your actual Rev.ai API keyconst apiKey ='02C_ac_fneC3eG3c8_xNokCR7HXwVyj2FJVMxO1evOHr02JtQ7SGOl7gBXW1Smn63vujWEdYpH-VoL8z8VBqWnwT5lWWw';// Replace 'https://api.rev.ai/revspeech/v1beta/speech' with the Rev.ai API endpointconst apiUrl ='https://api.rev.ai/speechtotext/v1';// Input for selecting the audio file in the browserconst audioFileInput = document.getElementById('audioFileInput');
audioFileInput.addEventListener('change', handleFileSelect);function handleFileSelect(event){const selectedFile = event.target.files[0];if(selectedFile){// Read the selected audio file using FileReaderconst reader =newFileReader();
reader.onload =function(e){const audioFileBase64 = e.target.result.split(',')[1];// Extract base64 data// Make a POST request to Rev.ai API
fetch(apiUrl,{
method:'POST',
headers:{'Authorization':`Bearer ${apiKey}`,'Content-Type':'application/json'},
body: JSON.stringify({media_url:'https://www.youtube.com/watch?v=1RWXHI4mm6E&ab_channel=PizzaMusic'})}).then(response =>{if(!response.ok){thrownewError(`HTTP error!Status: ${response.status}`);}return response.json();}).then(data =>{// Handle the transcription data
console.log(data);}).catch(error =>{
console.error('Fetch error:', error.message);});};// Read the file as data URL
reader.readAsDataURL(selectedFile);}}