Is it possible to play sound in the browser with a matlab web app?
Show older comments
I'm a researcher studying hearing and we use MATLAB to generate and play sounds to research participants. In light of the social distancing measures in response to COVID-19 our lab has stopped testing participants in person. I'd like to be able to convert our existing experiments to web apps using the matlab compiler, but have been unable to verify whether or not its possible to play sound on the client computer. (i.e. in the web browser running the app, not the host/server)
Does anyone know whether this is possible or supported?
8 Comments
Mohammad Sami
on 9 Apr 2020
Which version of matlab are you working with ?
Starting from R2019b, you can use the uihtml element to do almost anything you can do in a webpage.
Mohammad Sami
on 9 Apr 2020
I don't know if the other audio playback functionality is supported in the compiled webapp. Maybe someone else knows.
Mohammad Sami
on 9 Apr 2020
Example of audio playback
https://www.mathworks.com/help/matlab/ref/uihtml.html
rob mcleod
on 8 Sep 2020
Jordan I would be very interested to know if you managed to get this working? I am also researching hearing and having exactly the same problem.
Jordan Beim
on 8 Sep 2020
Benjamin Lentz
on 17 Feb 2021
Edited: Benjamin Lentz
on 17 Feb 2021
Hello Jordan,
I have the same problem as you did in April last year. I also tried to solve it with uithml. I managed to play sounds in the browser (with javascript and Audio objects, because I wanted it to play directly and not pressing any additional buttons), but:
- When I do not change the audio file name and overwrite the same audio to play different sounds, Firefox keeps playing the first one. I guess because the audio information is still in the cache. I tried many ways to delete the Audio object but it did not work.
- When I try to change the audio file names they cannot be played. I guess because as you say, one somehow has to wait before the file is buffered?
I have also tried to solve the second point but it did not work out so far. How did you do it? Could you maybe provide some code?
Jordan Beim
on 17 Feb 2021
Benjamin Lentz
on 18 Feb 2021
Hi Jordan,
thanks for your quick and detailed answer!
That's even more complicated than I expected. That must have been a lot work to figure out.
So as I understand, one keypoint is that MATLAB and the HTML (or Javascript) code have to interact frequently. They are checking a (re)action of the respective other side by waiting on changes of the Data field. I guess for this communication there should be only one HTML object created in the MATLAB Web App which is saved and reused?
I already found a nice documentation about the communication of MATLAB and HTML ( mathworks.com/help/matlab/creating_guis/create-an-html-file-that-sets-data-or-responds-to-data-changes-from-matlab.html ) and your explanations are quite helpful so I'm optimistic that it will work. Thanks a lot!
Answers (0)
Categories
Find more on Measurements and Spatial Audio in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!