Code Monkey home page Code Monkey logo

Comments (7)

chris--jones avatar chris--jones commented on June 11, 2024

This is the sort of challenge I'm up for.

from morse-decoder.

ozdemirburak avatar ozdemirburak commented on June 11, 2024

I'd be more than happy to accept your PR, @chris--jones.

from morse-decoder.

chris--jones avatar chris--jones commented on June 11, 2024

@ozdemirburak - I'm really close... I have a "working" wave export, branch is here: https://github.com/chris--jones/morsify/tree/wave-export

The complexity of wave conversion was taken largely from https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js so a lot of credit to @mattdiamond

I'm not satisfied yet though, because:

  • It uses the deprecated ScriptProcessorNode: https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode
  • It actually plays the audio to pipe it to the relevant node meaning that the export takes at least as long as the audio clip; this also has the side effect of interfering with the play functionality as I'm disconnecting from audio output and reconnecting when I'm done (attempting play in the middle of export may also interrupt the export).

I'm going to see if I can get this working via an OfflineAudioContext, but this will mean duplicating the audio nodes as you cannot connect them across contexts. This may not be a big deal, but if resource usage increases it might be better to expose the export interface as a separate construct so that the resources can be instantiated as required.

Finally I'd like to ask about the API itself - presently I'm returning the Blob object containing the wave data as this is the most flexible, however it will most likely be used via a call to URL.createObjectURL(blob); to either assign it to an audio player or start a download - so it might make sense to return this object url or even offer a convenience method to start a download.

from morse-decoder.

ozdemirburak avatar ozdemirburak commented on June 11, 2024

@chris--jones It is definitely great progress for the initial commit.

I think when someone calls the export method, it should start a download by default. But, maybe there can be an optional parameter for returning the blob object.

I'll also have a detailed look tomorrow. Thanks again.

from morse-decoder.

chris--jones avatar chris--jones commented on June 11, 2024

I have it working with OfflineAudioContext now and it works as I had hoped - exporting the file very quickly 👍

I will need to refactor a bit to maintain both contexts, and unfortunately OfflineAudioContext requires me to iterate over the morse to get the audio length to initialise the offline audio context, only for it to then have to iterate over the morse again to set the gain levels which I can't do until I get the gain from the context 😠 ...oh well.

If it sounds ok to you, I'll submit my PR once it's working via offline audio context and defer working on the migration to the newer AudioWorkletNode (https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletNode) as a separate issue as it looks like it may require externalising the processing audio node script so that it can be run as a worker thread which may mean multiple scripts in the solution (I'm guessing you prefer the simplicity of a simple file).

from morse-decoder.

ozdemirburak avatar ozdemirburak commented on June 11, 2024

Sure, sounds great. About the AudioWorkletNode, I am not familiar with it, but that definitely looks like an ideal solution.

from morse-decoder.

chris--jones avatar chris--jones commented on June 11, 2024

@ozdemirburak - I managed to solve it without using the deprecated script node as the offline audio context provides a buffer in the complete event. This site was a great help: http://joesul.li/van/tale-of-no-clocks/

I've added more details in the PR #17

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.