Unable to use p5.sound.js as an npm library
See original GitHub issueI would like to know how to use the sound library in the p5 npm module. I know the code is in there in a sub-folder called ‘addons’, but don’t know how to import or use it.
Currently I have
import p5 from 'p5'
and that works completely fine, I can do all the standard p5 things. But I have not been able to get it to work for any of the sound libraries.
Using the files directly from the p5js.org website
import p5 from './p5/p5.js'
works completely fine. But I have had no success with
import Oscillator from './p5/addons/p5.sound'
(or other such variants).
Any help will be greatly appreciated!
Issue Analytics
- State:
- Created 7 years ago
- Comments:14
Top Results From Across the Web
I can't seem to play sounds in javascript using p5.js - Libraries
I am new to Js, and p5 and I was trying to play a mp3 from my computer, but I continually get this...
Read more >P5.js not loading sound - Stack Overflow
Strange, the Sound: Load and Play Sound example seems to work fine. The error seems to point to on an XHR load error,...
Read more >p5 - npm
Install · Repository · Homepage · Weekly Downloads · Version · License · Unpacked Size · Total Files.
Read more >17.1: Loading and Playing - p5.js Sound Tutorial - YouTube
In this new video series, I discuss the p5. js sound library to work with audio. In this first part, I demonstrate how...
Read more >reference - P5.js
sound library. p5.sound extends p5 with Web Audio functionality including audio input, playback, analysis and synthesis. p5.SoundFile: Load and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the solution! It’s very simple. The following should do the trick.
import ‘p5/lib/addons/p5.sound’; import ‘p5/lib/addons/p5.dom’;
I found a somewhat hacky solution. My issues was that p5 was not defined when loading the p5 sound module. So after googleing the entire internet with no solution, I decided to try something dumb. I added
import p5 from "p5";
to the top of “p5/lib/addons/p5.sound”;then imported them as normal into my components
import p5 from "p5"; import "p5/lib/addons/p5.sound";
and it’s working so far
**update ** just kidding, only works in development since its already installed ended up loading both p5 and p5.sound as script tags in the head not ideal but after multiple hours of trying it the npm way this was the only thing that worked