discordier/sam

audiocontext not defined

Closed this issue · 4 comments

I'm currently trying to run this on my computer using Visual Studio Code. I have no experience so I've pretty much been throwing things at the wall and seeing what sticks.

When I run my .js file, I am met with
image
this error. I am unsure why, and don't know how to resolve it. Any help would be much appreciated : )

AudioContext is a standardized Web API (https://developer.mozilla.org/en-US/docs/Web/API/AudioContext).

However you seem to be running JS in node 21.7.1 which has only limited APIs available.
Maybe you can get further by utilizing https://github.com/audiojs/web-audio-api, yet I have no experience with that one.

The speak functionality of this library is intended and tested for browser usage (client side).
You might want to use the sam.buf32(); method to generate the byte buffer and send that to the client then.

In the end it depends on what you are trying to achieve.

I'm not trying to do much at this point, just get it working at all. My stuff consists of an html file directly linking to the script, which has the code snippet for copy-paste from here.

How do I load/convert the buffer into a hear-able mp3 or wav file after getting it?

Playing is to be done as in the play method (yet your error message above states you are NOT using an html file but are running from nodeJS)

You might want to have a look at the gh-pages branch, which contains all the examples as complete html files.

You provide way too few details of your setup and what you are doing. Sorry I can't provide basic webdev, Javascript and nodeJS support.
Maybe you want to upload your project to github and we can have a look at what you are doing.

Got it somewhat working!!! Figured out with a friend that the samjs script wasn't correctly importing into index.js (the one where the main things happen). Sort of fixed it by having index.html also link to the samjs script. We're not entirely sure why it wasn't importing, nor how to fix it.

Thanks.