peaks.js
peaks.js copied to clipboard
'AudioContext not allowed to start' in Chrome
Currently my app is using AudioContext to build the waveform on first play, and uploading said waveform to the node server for subsequent usages.
This because my users are uploading their own source audio files, know nothing about peaks.js (and nor should they), and I was unable to find a way to generate the waveform from inside my node.js server code. I would very much prefer for the server to generate the waveform on receipt of the uploaded audio, but was unable to figure out how to do it (the server runs as a Heroku dyno.) Any suggestions as to how to achieve this would be most welcome.
So when I create the AudioContext object is generates the following warning:
The AudioContext was not allowed to start. It must be resumed (or created) after a user
gesture on the page. https://goo.gl/7K7WLu
necessitating that I save a reference to said context, and call cxt.resume() from onPlay() as follows:
async onPlay() { if (this.cxt) this.cxt.resume(); this.peaks.player.play();
So whilst it works ok, I still get the annoying warning all the time, so I was hoping that it might be fixed at the source, so to speak.
many thanks for your wonderful software. gary
Hi Gary,
What I'd do is run the uploaded audio file through audiowaveform, then store the output .dat file somewhere it can be downloaded by your web application. In Node.js you could use child_process.exec to invoke audiowaveform. You might want to consider offloading this task to a worker via a message queue.
audiowaveform -i <filename>.mp3 -o <filename>.dat -b 8
I hope this helps, but please let me know if you need any more detail.
I took another look at trying to install audiowaveform into my heroku-based server, but I couldn't figure out how to specify the appropriate Aptfile entries. From the heroku docs:
# you can list packages
libpq-dev
# or include links to specific .deb files
http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise- amd64.deb
# or add custom apt repos
:repo:deb http://cz.archive.ubuntu.com/ubuntu artful main universe
Any clues as to what I'd need to specify to install audiowaveform would be much appreciated.
many tias.
I don't know Heroku, so this is a guess:
:repo:deb http://ppa.launchpad.net/chris-needham/ppa/ubuntu bionic main
or xenial instead of bionic for Ubuntu 16.04 rather than 18.04?
I took another look at trying to install audiowaveform into my heroku-based server, but I couldn't figure out how to specify the appropriate Aptfile entries. From the heroku docs:
# you can list packages libpq-dev # or include links to specific .deb files http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise- amd64.deb # or add custom apt repos :repo:deb http://cz.archive.ubuntu.com/ubuntu artful main universeAny clues as to what I'd need to specify to install audiowaveform would be much appreciated.
many tias.
Hi @stephensong
Were you able to successfully get audiowaveform on your heroku server to convert mp3 to wav /dat
Hi again,
So I finally found a round tuit, and tried to make installing audiowaveform on heroku ... alas no cigar.
remote: Reading package lists...
remote: W: GPG error: http://ppa.launchpad.net/chris-needham/ppa/ubuntu bionic InRelease: The
following signatures couldn't be verified because the public key is not available: NO_PUBKEY
4C1BCDE2763923D8
remote: E: The repository 'http://ppa.launchpad.net/chris-needham/ppa/ubuntu bionic InRelease'
is not signed.
remote: ls: cannot access '/app/tmp/cache/apt/cache/archives/*.deb': No such file or directory
Not sure if this if fixable ...
In the meantime, I tried using audiowaveform from my Windoze machine (for development purposes) ... no cigar again. Can't build it, and can't source a pre-built Windoze binary from anywhere, or so it seems.
And it's all actually become more urgent, because I've since found out that the using the AudioContext method doesn't work for large'ish files (like whole albums or podcasts).
So I'm starting to think I might have to find another player, despite really liking the peaks.js software, as also do my users, and my having sunk countless hours already into making it all work,
very saddening ...
Well, I bit the bullet and decided to have a go at creating my own node js code for creating the waveform. I have put it up as a public gist at:
https://gist.github.com/stephensong/781d59d8dec335f03f953c839e590160
I should point out that I've only tested it using single channel (version 1), but I am reasonably confident that it should work ok for multi-channel (version 2) also.
Again, many thanks for your wonderful software.