Code Monkey home page Code Monkey logo

Comments (5)

chris--jones avatar chris--jones commented on June 3, 2024 1

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.

chris--jones avatar chris--jones commented on June 3, 2024 1

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>

image

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.

salmanAhmad143 avatar salmanAhmad143 commented on June 3, 2024

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

image

const audio = morse.audio('My Text');

if(notPlaying) {
     audio.play();
} else {
     audio.stop();
}

Please suggest any one. Waiting for your reply.

from morse-decoder.

ozdemirburak avatar ozdemirburak commented on June 3, 2024

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.

ozdemirburak avatar ozdemirburak commented on June 3, 2024

That's a really smart approach.

from morse-decoder.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.