<script src="soundmanager2.js"></script><script>// where to find flash SWFs, if needed...soundManager.url = '/path/to/swf-files/';
soundManager.onready(function() {soundManager.createSound({id: 'mySound',url: '/path/to/an.mp3'});
// ...and play itsoundManager.play('mySound');});</script>
function playSound(url) {var ourAudio = document.createElement('audio'); // Create a audio element using the DOMourAudio.style.display = "none"; // Hide the audio elementourAudio.src = url; // Set resource to our URLourAudio.autoplay = true; // Automatically play soundourAudio.onended = function() {this.remove(); // Remove when played.};document.body.appendChild(ourAudio);}
<!DOCTYPE html><html><head><title>js prompt AI</title><style>#button {border: 1px solid black;border-radius: 10px;font-size: 22px;height:65px;width:100px;text-align: center;line-height: 65px;}</style></head><body>
<audio id="myAudio" src="./how_are_you.m4a"></audio><p>To Interact with the AI please click the button</p><div id=button>click</div>
<script>
var button = document.getElementById("button");function playBack() {button.addEventListener("click", function (){var talk = prompt("If you wish for the AI to respond type hi");var myAudio = document.getElementById("myAudio");
if(talk === "hi") {myAudio.play();}}) ;
}playBack();</script></body>
</html>
<audio id="welcome"><source src="URL/welcome.ogg" type="audio/ogg"><source src="URL/welcome.mp3" type="audio/mpeg">Your browser does not support the audio element.</audio>