I have a .wav that I want to play when a person clicks on a link. How do I go about doing that? I'm not exactly an expert at html or css or javascript so be gentle with me
Reference
Playing audio with Javascript?
Example
Two Links
Play
Stop
jQuery click Events
$(document).ready(function(){
var audio;
$("a.playButton").click(function(){
console.log("playing");
audio = new Audio('http://download.wavetlan.com/SVV/Media/HTTP/WAV/Media- Convert/Media-Convert_test1_Alaw_Mono_VBR_8SS_16000Hz.wav');
audio.play();
});
$("a.stopButton").click(function(){
console.log("Pause");
audio.pause();
});
});
Now this probably isn't the most accurate way to do this but it gives you an idea of how this works. If you want to use the built in audio tag you can do that too cause that will give you the controls and other helpful things.
JSFIDDLE
https://jsfiddle.net/pzth1zd5/
Related
One of my goals with learning dialogFlow and programmatic webhooks to handle intens and responses is to see if it's possible to create an audio rich quiz.
In this quiz there's a section where I would like to have multiple questions/responses with a continuous audio background playing at the same time. Is this possible or must the Google Assistant or Google Home Speaker be silent when waiting for user input?
Also, if it is possible with the above, is it also possible to make crossfades between audio backgrounds triggered by events of some kind? That is like a change of scenery without interruption/silence.
There are a number of approaches to this, depending on your exact needs and limitations you have. Not everything is completely possible, but you may be able to get close.
Dialog with Background Audio
The easiest way to do this would be to use Google's version of SSML with parallel elements using the <par> and <media> tags. (But be aware that these are non-standard tags, if you want to be able to use them elsewhere.) With this, you would have one "track" for the dialog and one for the audio. It might look something like this:
<speak><par>
<media xml:id="track-0" begin="0s" soundLevel="+0dB">
<audio src="https://actions.google.com/sounds/v1/crowds/crowd_talking.ogg" >crowd talking</audio>
</media>
<media xml:id="track-1" begin="0.75s" soundLevel="+0dB">
<seq>
<media>
<speak><p>Well, hello there</p></speak>
</media>
<media begin="2.0s">
<speak><p>How are you?</p></speak>
</media>
</seq>
</media>
</par></speak>
Is there an easy way to design this?
You might want to check out the Nightingale Visual SSML Editor which has also been released as an open source project. It can help get you started, but tweak the SSML yourself.
What about cross-fades?
Sure! Just indicate that you're fading one track out, and fading another in, starting at some offset to the end of the other track.
<speak><par>
<media xml:id="track-0" begin="0s" fadeOutDur="6s">
<audio src="https://actions.google.com/sounds/v1/alarms/digital_watch_alarm_long.ogg" >digital watch alarm long</audio>
</media>
<media xml:id="track-1" begin="track-0.end-6s" fadeInDur="6s">
<audio src="https://actions.google.com/sounds/v1/human_sounds/baby_cry_long.ogg" >baby cry long</audio>
</media>
</par></speak>
And I can have this playing while the microphone is open and listening to a user?
Well... no. Not with SSML.
If you think about this as a conversation with someone, we typically require audio cues to know when to speak. Asking a question and then giving quiet space to reply is an excellent way to do this. In person - we have other cues (we can see the other person pause, for example), but if we just have audio, we only have silence.
The Assistant works based on this sort of conversational model, so wants to make it clear to the user when it is their turn to speak.
You can argue that for some kinds of "conversations", it is normal to have a different audio cue that prompts the user. And you'd be correct. But the Assistant needs to be a general-purpose Assistant.
Then how can I do this?
Since you're making a quiz, you can use the Interactive Canvas to create a page with HTML and JavaScript. With this, you can use an <audio> tag or the MediaStream JavaScript API to create the background audio. With this, you can have the microphone open while this media still plays, but there isn't any event that lets you know when the mic is open so you can duck the audio, which is a bit of a downside.
This gets around the audio-cue issues because there are visual cues when the microphone is open.
You can also use the SSML <mark> tag to trigger events in your JavaScript so you know when the SSML from the server begins, ends, or hits other points in the audio stream.
If there are visual cues, can I use the Interactive Canvas on a smart speaker?
Well... no.
But what you can do is use runtime surface capabilities to determine if the Interactive Canvas is supported.
If it is - use it (possibly along with SSML).
If not, use the SSML method.
So I would like to host audio files on my server.
Here's how I do it.
app.use("/media/audio", express.static("media/audio"));
I have done it tons of times with images and I really haven't had a problem so far.
I am able to play these files in browser but I need little more than that.
I am not even sure how to describe it but what I need is this:
My URL only returns media player but nothing in Sources tab like shown in the picture.
The only reason I want it is because Android MediaPlayer cannot return .mp3 file just because the URL ends with .mp3. Apple doesn't have a problem with that and it plays fine.
instead of app.use("/media/audio", express.static("media/audio"));
use
app.use("/media/audio", (req, res)=>{
res.download("/media/audio.mp3");
});
On this page, if you click any "Watch Video" button, it opens a video. If you hit play and then hit Close, the audio keeps playing. Googling makes it seem like it's just something Google needs to fix, but curious if anyone knew of any way to stop it
jQuery(document).ready(function($) {
$("#hp-video").on('hidden.bs.modal', function (e) {
$("#hp-video iframe").attr("src", $("#hp-video iframe").attr("src"));
});
});
That did the trick (with the proper ID of course)
this happens alot to me and i soon found out how to do it.
just turn off the autoplay and turn off the audio of youtube.
and it wont autoplay the next vid and there is no audio on the vid
I want to play a sound from a Chrome Extension, but I read that Content Scripts cannot play sounds. So I put this code in my background script:
var audio = new Audio("alert.ogg");
audio.play();
but still no sound. From the Console of the _generated_backgound_page.html I was able to inspect the Network tab and see that the sound file is loaded successfully, but I hear nothing.
Also, in another HTML page, I could load another Javascript, which has the above code, and it works (I can hear the sound.)
The fact that it is in the background script seems to have made it fail. Also, note that I do not have a background PAGE associated with the background SCRIPT. Does that matter?
edit: problem solved. The above code works but I forgot to listen to the right sound output channel.
You can generate the background page with javascript. I think the sound must be in a html page to be loaded and played.
This should work:
document.write('<audio id="player" src="data:audio/wav;base64,UklGRhwMAABXQVZFZm10IBAAAAABAAEAgD4AAIA+AAABAAgAZGF0Ya4LAACAgICAgICAgICAgICAgICAgICAgICAgICAf3hxeH+AfXZ1eHx6dnR5fYGFgoOKi42aloubq6GOjI2Op7ythXJ0eYF5aV1AOFFib32HmZSHhpCalIiYi4SRkZaLfnhxaWptb21qaWBea2BRYmZTVmFgWFNXVVVhaGdbYGhZbXh1gXZ1goeIlot1k6yxtKaOkaWhq7KonKCZoaCjoKWuqqmurK6ztrO7tbTAvru/vb68vbW6vLGqsLOfm5yal5KKhoyBeHt2dXBnbmljVlJWUEBBPDw9Mi4zKRwhIBYaGRQcHBURGB0XFxwhGxocJSstMjg6PTc6PUxVV1lWV2JqaXN0coCHhIyPjpOenqWppK6xu72yxMu9us7Pw83Wy9nY29ve6OPr6uvs6ezu6ejk6erm3uPj3dbT1sjBzdDFuMHAt7m1r7W6qaCupJOTkpWPgHqAd3JrbGlnY1peX1hTUk9PTFRKR0RFQkRBRUVEQkdBPjs9Pzo6NT04Njs+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IGAgYGBgoGCgYKBgoGCgYKBgoGCgoKDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KDgoOCg4KCgoGCgYKBgoGCgYKBgoGCgYKBgoGCgYKBgoGCgYKBgoGCgYKBgoGCgYKBgoGBgYCBgIGAgYCBgIGAgYCBgIGAgYCBgIGAgYCBgIGAgYCAgICBgIGAgYCBgIGAgYCBgIGAgYCBgExJU1RCAAAASU5GT0lDUkQMAAAAMjAwOC0wOS0yMQAASUVORwMAAAAgAAABSVNGVBYAAABTb255IFNvdW5kIEZvcmdlIDguMAAA" >');
document.getElementById('player').play();
I used a base64 audio file but you can use a normal file too.
I'm trying to create a mobile ready audio player. However, I'm wondering if it's possible to "mask" the src so that a user couldn't view source and download the mp3. I'm definitely a n00b, so any simple direction would be extremely helpful (IE - use 'x' to do 'y'). I don't necessarily need code examples. Thanks!
Current:
<audio src="unreleased_track01mp3">
...
</audio>
What I'd like:
<audio src="01238134781239871">
...
</audio>
No.
You could attempt to stream the audio, but if you want to play a specific file, the user will always be able to download it if the user is able to listen to it.