Community Tip - You can change your system assigned username to something more personal in your community settings. X
I have a customer that wants to have non-voice sounds in HL2. Something like "ding" or similar. There isn't an audio widget in the options in studio for the 3D canvas.
We have been using the following line of code to synthesize speech but want some non-speech sounds:
$scope.app.speech.synthesizeSpeech({'text': 'Say this text out loud'});
On a related note, can you change the voice that gets used by that line of code?
use this code
$scope.mp3play=function() {
var audioElement;
if(!audioElement) {
audioElement = document.createElement('audio');
audioElement.innerHTML = '<source src="' + 'app/resources/Uploaded/File_Name.mp3'+ '" type="audio/mpeg" />'
}
audioElement.play();
};
File:Name.mp3 = file audio uploaded into project.
i hope to help you.
Hi @Giuseppe_Fiore .
I tried your code. It worked really well. Just one question i have a button which is linked to playing sound. When i press the button sound plays and ends after 10 seconds but when i click the button again before 10 seconds previous sound and the new sound mixes. Can you please tell me a way in which i can allow the first sound to play completely and then only second will be played.
Thank you
Hi @vivekse ,
you can simple define a listener for the play finish- some thing like this:
//==================================
$scope.app.playAudio = function (mp3) {
var audio = new Audio(mp3);
audio.addEventListener('ended', function() {
console.warn("mp3="+mp3+" finished!")
console.warn("call the next audio from the list");
}, false);
audio.play();
};
// and later use it e.g.
$scope.toggleClick= function()
{
console.log("toggleClick");
$scope.app.playAudio('app/resources/Uploaded/seq_step_'+GetCurrentStep()+'.mp3');
For example you can write all mp3 files in an array and play the next :
var mp3arr = ["step1.mp3", "step2.mp3", "step3.mp3", "step.mp3"];
function getNext(mp3arr, mp3) {
var index = mp3arr.indexOf(mp3);
return mp3arr[index+1]
}