{"action":"closed","issue":{"url":"https://api.github.com/repos/chris-rudmin/opus-recorder/issues/119","repository_url":"https://api.github.com/repos/chris-rudmin/opus-recorder","labels_url":"https://api.github.com/repos/chris-rudmin/opus-recorder/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/chris-rudmin/opus-recorder/issues/119/comments","events_url":"https://api.github.com/repos/chris-rudmin/opus-recorder/issues/119/events","html_url":"https://github.com/chris-rudmin/opus-recorder/issues/119","id":284603242,"number":119,"title":"Using the decoder in a SPA","user":{"login":"phal0r","id":3658211,"avatar_url":"https://avatars3.githubusercontent.com/u/3658211?v=4","gravatar_id":"","url":"https://api.github.com/users/phal0r","html_url":"https://github.com/phal0r","followers_url":"https://api.github.com/users/phal0r/followers","following_url":"https://api.github.com/users/phal0r/following{/other_user}","gists_url":"https://api.github.com/users/phal0r/gists{/gist_id}","starred_url":"https://api.github.com/users/phal0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phal0r/subscriptions","organizations_url":"https://api.github.com/users/phal0r/orgs","repos_url":"https://api.github.com/users/phal0r/repos","events_url":"https://api.github.com/users/phal0r/events{/privacy}","received_events_url":"https://api.github.com/users/phal0r/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-12-26T20:00:16Z","updated_at":"2017-12-30T20:45:37Z","closed_at":"2017-12-30T20:45:36Z","author_association":"NONE","body":"Hi,\r\n\r\nthanks for this piece of software. It really helps me in my current project, where I need to encode several user recorded audio files. The encoder is working really smooth and I am trying to use the decoder for browsers like Safari and managed to produce this code:\r\n\r\n```\r\nvar typedArray = new Uint8Array(buffer);\r\n    var decodedData = [];\r\n    that.decoder.onmessage = function(e){\r\n      // null means decoder is finished\r\n      if (e.data === null) {\r\n        var raw = new Float32Array(decodedData.length * 4096);\r\n        for(var i=0,len=decodedData.length;i<len;i++) {\r\n          raw.set(decodedData[i], i * 4096);\r\n        }\r\n        var audioBuf = Wad.audioContext.createBuffer(1, raw.length, Wad.audioContext.sampleRate);\r\n\r\n        if (typeof audioBuf.copyToChannel === \"function\") {\r\n          audioBuf.copyToChannel(raw, 0, 0);\r\n        } else { // Safari, Edge sometimes\r\n          audioBuf.getChannelData(0).set(raw);\r\n        }\r\n        console.log(audioBuf);\r\n        that.decoder.onmessage = null;\r\n        return resolve(audioBuf);\r\n      }\r\n      // e.data contains decoded buffers as float32 values\r\n      else {\r\n        decodedData.push(e.data[0]);\r\n      }\r\n    };\r\n    that.decoder.postMessage({\r\n      command: 'decode',\r\n      pages: typedArray\r\n    }, [typedArray.buffer] );\r\n\r\n    that.decoder.postMessage({\r\n      command: 'done'\r\n    });\r\n```\r\n\r\nBasically taken from your decoding example, but modified it to use it as an AudioBuffer directly instead of encoding it to wav. This works so far, but after sending the 'done' command \r\n\r\n```\r\n    that.decoder.postMessage({\r\n      command: 'done'\r\n    });\r\n```\r\nThe decoder worker closes itself. The encoder just sends one message, once encoding is finished, so it is easy to keep the worker alive and detect the end of the encoding. The decoder in contrast needs the 'done' command to send an empty message as marker of the end of decoding. Is there an intended way to keep the worker alive to use it for decoding several audio files while the app is running?\r\n\r\nThanks in advance!"}}
{"actor":{"display_login":"chris-rudmin"}}