Jarvis audio-player

by velo_ninja

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Audio Player Example</title>
</head>
<body onload="init();" style="background-color:lightgray;">
  <button onclick="playAudio()">ACTIVATE-JARVIS</button>
  <script>    
    function init () {
      // when a message is received from the page code
      window.onmessage = (event) => {
        if (event.data) {
          console.log("HTML Code Element received a message!");
          console.log(event.data);
          let binaryAudioData = event.data;
          playAudio(binaryAudioData);          
        }
      }
    }      
   
   async function playAudio(binaryAudioData) {
    // Convert the array of integers to Uint8Array and then to ArrayBuffer
    const uint8Array = new Uint8Array(binaryAudioData);
    const arrayBuffer = uint8Array.buffer; console.log(arrayBuffer);
    // Create a new AudioContext.
    const audioContext = new (window.AudioContext || window.webkitAudioContext)();
    try {
      // Decode the binary audio data into an audio buffer.
      const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
      // Create an AudioBufferSourceNode.
      const source = audioContext.createBufferSource();
      // Set the buffer of the AudioBufferSourceNode to the decoded audio buffer.
      source.buffer = audioBuffer;
      // Connect the AudioBufferSourceNode to the AudioContext destination (speakers).
      source.connect(audioContext.destination);
      // Start playing the audio.
      source.start();
    } catch (error) {console.error('Error decoding audio data:', error);}
  }
   
  </script>
</body>
</html>

JavaScript

//uQxAAAD5GBH6GMbepnMaNxhJohAKKaTikZLbgAVDigAglAABABCotn3FhBAcWgGaFAgAToAFCeFmhBxbwALBgZ199/P0RH+hwM90v6FEAxb133M0osIIoGwvDgbhwNkiABOfTDgYvgAIDi/Dgbi4AEETl0rgChz3cEAAYHC4AELQRxETw4GxcSiwARX8AH+PUdl0idKqMgODio1hwRliE15AUMWQpK4rAoyhAiG1hIhk3qZtVbIHRYSh4E0IGhRIofwlgow5AmQUyuw0YtFQewgbBbTNr4nBNjFiPRVXAlzF2ii5xqY9BcOcWsIrZH/osUjMCF6g3jF3v2Wy3q8Xrd8aHiLZrczMTleGpubreISjnJ39ZHCE2SNKnE1GL2N0NemxF9k5E1VXWVAAhAABcxRFyD+AcUKJ8Ocqk4Xs4w7iTksN1FJ5AtygeplHIqEQ0IiQNBtq1UTKSScnyxohIiVtCqorJYqSskBkyoXWLdW/zb3STYQ1ATKDa+rICUyTKOQT3UB2TRtAouykcguWmmaVaYtphHKWE6TFrQ1ADt//uSxDqA1c2XEwe9I8LlM6IVhiUwlzDTB08wO6s2s0jjeqnciUjThFA4fyaR+yacmT+TMxqJVZZHW0VVXPXSbsZ6mpQ/XkFhCSJlvoO9IMH8ImS5dSjCZkOv8rmHwGhOfFcQRLDkXEY5PjA7KxMIRkVlyAFWgfKWCDyM8Sn0YkEJNJOAjxMCB8WMqmGXpUzyiJE6wXRstost7aISti5CDZuCGoQI0jZUVQQEUUCb0kIOzVXJDTkBovBc3kTkSeYaANFGMysvGiMZ1VwCE5526AVghcSNlwqYeKZyKKHRQcrT5G6bdclUTQsUXXcoh3E04E6scMEG46NEOLsR2eIRCaaRyKFOc5tyEgAAM4UhhE6YnYd5lGi/Ok4VQiEksH23KptshS2m0wpjLQmEwCLkAUCh1ssJjSpCnBQtBggJhK0K1UmDxCzHVizaXIjaa9aaJGKjELLQIW0CGZliAvNEkjissXWHsQzcrCNFt85Nqj5DbOhBaj0DyOpgqYiTw/xEkwSYUaksiRK40oCI9K0CJxmXtGnw3N1M36qTgLV2R0ot9f8=



/*
async function playSound(binaryAudioData) {
      // Create a new AudioContext.
      const audioContext = new (window.AudioContext || window.webkitAudioContext)();
      // Decode the binary audio data into an audio buffer.
      const audioBuffer = await audioContext.decodeAudioData(binaryAudioData);
      // Create an AudioBufferSourceNode.
      const source = audioContext.createBufferSource();
      // Set the buffer of the AudioBufferSourceNode to the decoded audio buffer.
      source.buffer = audioBuffer;
      // Connect the AudioBufferSourceNode to the AudioContext destination (speakers).
      source.connect(audioContext.destination);
      // Start playing the audio.
      source.start(); 
    } 
    
    
 */