advanced audio control

advanced audio control

by Adam Murray -
Number of replies: 15

Long time Moodle user, first time poster.

I am working on setting up audio quizzes for my students for listening practice and I have been looking for a simple way to have advanced audio controls (i.e. Playbackrate) so that they can reduce or increase playback speed. I have done a fair amount of searching and have looked at a number of options such as jw player, flowplayer etc...

I think I have made a breakthrough and cobbled together some Javascript for jQuery. It seems to look okay but when I attempt the quiz, it only plays about 5 seconds of the audio and then stops. However, when I review the quiz results, the playback seems fine. Any suggestions?

I am using 2.7 and have attached a screenshot to show what it looks like.

Thanks in advance!

Adam

Average of ratings: -
In reply to Adam Murray

Re: advanced audio control

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Adam,

Looks interesting. I haven't the foggiest on how to solve the play time but I am always interested in trying out any audio/video items used in Moodle. Since both PoodLL and Nanogong are usable in quizzes, maybe a look at their code could be of some help.

I know that both of them work great and especially PoodLL is usable about anywhere in Moodle, not just the quizzes. So far as I know, PoodLL does not let you slow down or speed up the audio, but Nanogong does. In fact Nanogong speeds up or slows down 50%, without a change in pitch.

AL

In reply to AL Rachels

Re: advanced audio control

by Adam Murray -

AL,

Thanks for the reply. I initially contacted the PoodLL developer because I hoped that would be the solution that I needed. Unfortunately, as you mentioned, it doesn't control speed. I have spent a couple hours playing with Nanogong and it looks promising. However, I am getting these error messages:

get_context_instance() is deprecated, please use context_xxxx::instance() instead.
  • line 3670 of /lib/deprecatedlib.php: call to debugging()
  • line 61 of /mod/nanogong/view.php: call to get_context_instance()
add_to_log() has been deprecated, please rewrite your code to the new events API
  • line 48 of /lib/deprecatedlib.php: call to debugging()
  • line 64 of /mod/nanogong/view.php: call to add_to_log()

I am using 2.7 so I suspect that is the source of the problems.

Adam


In reply to Adam Murray

Re: advanced audio control

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Adam,

Fixing the deprecated get_context_instance is easy, but the add_to_log is much more involved. On a temporary basis they can be ignored.

If you want to fix the first one, edit    ..yourmoodle/mod/nanogong/view.php, change line 61 from:

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

so that it is like this:

$context = context_module::instance($cm->id);

Save your change, then reload the page and that get_context_instance warning should disappear.

Fixing the log entry is much more involved, and I just don't have the time to dig into it right now. Hopefully the developers will come out with a Moodle 2.7 version before too long.

AL
In reply to AL Rachels

Re: advanced audio control

by Adam Murray -

AL,

Thanks for the reply. I suspected that the change would involve some effort. I am somewhat of a dabbler so I will make the first change to the code. I have emailed the developers via the link on their website and hopefully they will respond.

Adam


In reply to Adam Murray

Re: advanced audio control

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

I was thinking about this. A simple solution to this could be to create separate audio files for each speed. Then use a one button player, PoodLL mini player or html5 audio or something, to play each one back. You could lay it out as in your screenshot. 


Then you would not have to spend forever trying to fix up nanogong or getting all tangled up with another player.

Average of ratings: Useful (1)
In reply to Justin Hunt

Re: advanced audio control

by Adam Murray -

Justin,

Having multiple recordings would be an easy solution but the student would have to choose which recording to listen to (ie. midway through the listening, they wouldn't be able to slow it down and then increase it to regular speed again). I agree that I certainly want to get bogged down with a specific player.

Adam


In reply to Justin Hunt

Re: advanced audio control

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Right. You wouldn't be able to do that. A cross platform solution to this would be the best. I came across this:

http://www.w3schools.com/tags/av_prop_playbackrate.asp

Though I haven't tried it. This could be good because it will work on most browsers/os and devices. I don't know if setting the playback speed in real time will work.  Needs a bit of research.



 

In reply to Justin Hunt

Re: advanced audio control

by Adam Murray -

Justin,

PlaybackRate certainly seems to be the solution. I will mess around with it some more. Here's a nice little demonstration of what is possible. In the case of language learners, a playbackRate of .8 or .75 would reduce the speed without reducing intelligibility. I was thinking a little turtle icon would be nice and then a rabbit icon for 1.2 or so.

Without any further ado, here's the link

http://hyperaud.io/lab/pbr-test/

Adam

In reply to Adam Murray

Re: advanced audio control

by Adam Murray -

Justin,

This is the code that I came up with and it seems to work fine within Moodle quizzes (as far as I can see).

---
<button onclick="SlowSpeed()" type="button">75% (Turtle)</button>
<button onclick="RegularSpeed()" type="button">100% (Turtle)</button>
<button onclick="FastSpeed()" type="button">125% (Rabbit)</button>
<br>
<audio id="audio1" controls="controls">
  <source src="http://www.ukumillion.com/audio/1.mp3" type="audio/mpeg">
  Your browser does not support HTML5.
</audio>

<script>
myVid=document.getElementById("audio1");
function SlowSpeed()
  {
  myVid.playbackRate=0.75;
  }
function RegularSpeed()
  {
  myVid.playbackRate=1;
  }
function FastSpeed()
  {
  myVid.playbackRate=1.25;
  }
</script> 

---

Of course, this solution would mean inserting code into each and every question. Tedious, but doable because I probably have only about 30 or so questions in the course. There must be a better solution...

Adam


In reply to Adam Murray

Re: advanced audio control

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Awesome stuff!!! That is really cool

I think you can avoid pasting it on each page. This is a good job for the generico filter. Which I finished but haven't released yet. So nobody knows about it. Basically you create "templates" and then put the filter string in your html area, and then the generico filter expands them. It is here:

https://github.com/justinhunt/moodle-filter_generico

Bear in mind that on the question page, multiple questions could be present, so you would want to avoid the javascript functions being declared multiple times. Or you could be stern, and just put one question per page.

In reply to Justin Hunt

Re: advanced audio control

by Adam Murray -

Justin,

That would be awesome to not have to cut and paste code smile I was leaning towards having one question per page to avoid redundant javascript.

Adam

P.S. so are you looking for testers for your filter?

In reply to Adam Murray

Re: advanced audio control

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

 I thought the Generico filter would just prevent you having to paste code many times, which would be a drag, but which would also be terrible to maintain.

It would be nice to get someone to test it though. I just have not had time to document it better and "release" it. I was going to make a companion Atto plugin for it. 

Probably best not to confuse this thread too much with Generico. If you do use it, perhaps we can talk over email about all that. 

In reply to Justin Hunt

Re: advanced audio control

by Adam Murray -

Will do. Just to wrap this thread up (and for people that may be interested in Generico - it certainly works and even a noob like me was able to figure it out)