Comments (5)
I haven't seen this happen before my only guess is some sort of race condition.
The current implementation of play/stop is kind of broken because AudioBufferSourceNodes aren't supposed to have start and stop called more than once - so audio.stop() is probably more of a dispose.
To make functionality similar to what you're expecting would require some refactoring in the library - only calling start for the first play on the source, tracking the currentTime (should be exposed I guess) and either altering the playRate or gain to simulate a pause on stop rather than outright stopping the source (although we'd still want a clean way to dispose of the audio source).
The current workaround is to create new audio instances when you play:
let audio;
if(notPlaying) {
audio = morse.audio('My Text')
audio.play();
} else {
audio.stop();
}
note this won't enable you to pause and resume though.
from morse-decoder.
I know this is closed, but it also occurred to me that you can use the wave functions to get an audio blob that you can pause, play and seek to your heart's content.
As an example consider this which binds the rendered audio to an audio element with controls:
<audio id="morse" controls />
<script>
const morse = window['morse-decoder'];
const audioOutput = morse.audio('Go ahead, pause this audio');
audioOutput.getWaveUrl().then((url) => {
document.querySelector('#morse')
.setAttribute('src', url);
});
</script>
I'll submit a PR to add more examples to the readme, since there's a few other omissions such as how to even use the minified js on a web page as I have above.
from morse-decoder.
Hey @phpsollution @ozdemirburak @chris--jones
Have you got the solution?
I am also facing the same error when i am trying to stop the morse it giving me the same error
const audio = morse.audio('My Text');
if(notPlaying) {
audio.play();
} else {
audio.stop();
}
Please suggest any one. Waiting for your reply.
from morse-decoder.
Chris' response should work as a workaround; therefore, I'm closing this issue. However, another issue can be opened for adding the pause/play option.
Completely refactoring the audio generation is another option. There are other potential changes mentioned here on #27.
from morse-decoder.
That's a really smart approach.
from morse-decoder.
Related Issues (16)
- Thai Alphabet HOT 3
- End of audio detection HOT 1
- Ukrainian leter "ґ" is missing HOT 2
- Error HOT 1
- Export Morse Code Audio to WAV HOT 7
- oscillator of null HOT 3
- Sending request HTTP request to https://morsedecoder.com/ HOT 2
- Migrate Code to TypeScript HOT 4
- Split Typescript logic into several files HOT 3
- Hatalı tanımlama HOT 2
- Modify Options - Add WPM and Volume Parameters HOT 4
- Proposed API updates to audio functions HOT 12
- Transpile ES5 to ES6 HOT 2
- The text is mixed up in places for buttons "dot" and "dash" on https://morsedecoder.com/learn-morse-code/ HOT 1
- Can't Play the Audio More Than Once in Safari Mobile (Web Audio API) HOT 6
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 morse-decoder.