Comments (1)
There are two issues with your code:
- npm packages needs a url to be retrieved
- you need to play audio after a user interaction
This code will work (tested on codepen). In this example I used unpkg.com, but any other service could work:
<html>
<body>
<button id="btn">play</button>
</body>
<script type="module">
import { Soundfont } from "https://unpkg.com/[email protected]/dist/index.mjs"; // needs to be a url
const context = new AudioContext(); // create the audio context
const marimba = new Soundfont(context, { instrument: "marimba" }); // create the player
document.getElementById("btn").onclick = () => {
context.resume(); // enable audio context after a user interaction
marimba.start({ note: 60, velocity: 80 }); // play the note
}
</script>
</html>
Feel free to reopen if you still have problems.
from smplr.
Related Issues (20)
- When scheduling large number of notes, no sounds is being output HOT 14
- Outdated Documentation HOT 1
- onEnded has stopped working with version 0.10 HOT 2
- Playing notes does extra logging in the console HOT 2
- setVolume and reverb effect no longer working. HOT 4
- Version 0.11.0 - onStart does not fire when added to player.start({}) HOT 3
- Store the SoundFont objects in a list, and cannot reference them
- ElectricPiano.start fails silently without velocity parameter
- Support for using standarized-audio-context HOT 8
- Feature change not included in recent package published HOT 1
- TX81Z from ElectricPiano 404 HOT 3
- loading mp3 file HOT 1
- Non-integer note values do not work with Soundfont class HOT 4
- Playing back mp3 in Buffer - onEnded doesn't fire HOT 2
- Drum Machine: Roland missing ogg files, sampleNames issue with MFB-512 HOT 4
- Providing frequency for playback instead of notename/noteNumber HOT 5
- Error while importing Soundfont HOT 2
- Doesn't work (no sound) in mobile Safari and Chrome HOT 2
- Ideas to handle clicking when looping and custom soundfonts HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smplr.