Code Monkey home page Code Monkey logo

Comments (7)

chris-rudmin avatar chris-rudmin commented on July 2, 2024

The recorder object is intended to be reused and thus holds onto the stream
and the users permissions. The code you provided will stop the stream
properly, if you want the memory to be freed, you should also remove all
your event listeners as well. Javascript doesn't provide a nice way to
destroy objects so I left it out. When the recorder stops, the workers are
destroyed and the audio nodes disconnected from the destination so the
memory usage should minimal, and no extraneous events should be firing. Let
me know if this is in line with what you experience.

On 4 May 2015 at 16:09, Kequc [email protected] wrote:

The first time an instance of Recorder is created, the user is asked for
access to their microphone. In chrome this adds a red icon to the tab.
There isn't any way seemingly to end the stream.

In my application I'm creating a new Recorder instance each time I want to
record, is this an incorrect way to do things? I've added this.

recorder.addEventListener 'stop', =>
if recorder && recorder.stream
recorder.stream.stop()

It would be nice if I could de-initialise the stream as an intended
feature of the library.


Reply to this email directly or view it on GitHub
#13.

from opus-recorder.

chris-rudmin avatar chris-rudmin commented on July 2, 2024

Forgot to say thanks for your comment, and I will consider adding a destroy() method if It could be implemented nicely.

from opus-recorder.

Kequc avatar Kequc commented on July 2, 2024

The reason I suppose I bring it up is that users might be confused and think their browser is still listening to them. Which it could. I love this library by the way, I was dealing with just raw pcm before I found this. Good work, everyone past and present who has worked on it.

from opus-recorder.

Kequc avatar Kequc commented on July 2, 2024

Here is my solution to do what I wanted. Taking into consideration that you said the Recorder is intended to be reused.

_closeStream: =>
  # Close recorder stream

  if @recorder && @recorder.stream
    @recorder.stream.stop()
  @status.ready = false

start: =>
  # Start recording
  return false if @status.active || @status.ready

  @status.active = true

  if @recorder
    @recorder.initStream()

  else
    @recorder = new Recorder
      recordOpus:
        stream: true

    @recorder.addEventListener 'streamReady', =>
      if @status.active
        @status.ready = true
        @recorder.start()
      else
        @_closeStream()

    @recorder.addEventListener 'stop', =>
      @_closeStream()

  true

stop: =>
  # Stop recording
  return false unless @status.active

  @status.active = false

  if @recorder
    @recorder.stop()

  true

The idea is that a stream is closed when the recorder is stopped and a new stream is initialised on start. This serves my needs. I hope it's not too messy looking.

from opus-recorder.

chris-rudmin avatar chris-rudmin commented on July 2, 2024

Looks good. I believe you can safely call start and stop and if recorder
is not in the right state nothing will happen. Recorder is also storing its
state in recorder.state (inactive, recording, or paused) if you want to
read from it as well.

On 5 May 2015 at 11:55, Kequc [email protected] wrote:

Here is my solution to do what I wanted. Taking into consideration that
you said the Recorder is intended to be reused.

_closeStream: =>

Close recorder stream

if @recorder && @recorder.stream
@recorder.stream.stop()
@status.ready = false

start: =>

Start recording

return false if @status.active || @status.ready

@status.active = true

if @recorder
@recorder.initStream()

else
@recorder = new Recorder
recordOpus:
stream: true

@recorder.addEventListener 'streamReady', =>
  if @status.active
    @status.ready = true
    @recorder.start()
  else
    @_closeStream()

@recorder.addEventListener 'stop', =>
  @_closeStream()

@recorder

stop: =>

Stop recording

return false unless @status.active

@status.active = false

@recorder.stop()

The idea is that a stream is closed when the recorder is stopped and a new
stream is initialised on start. This serves my needs. I hope it's not too
messy looking.


Reply to this email directly or view it on GitHub
#13 (comment)
.

from opus-recorder.

chris-rudmin avatar chris-rudmin commented on July 2, 2024

Heads-up that i have experienced empty buffers when starting recording
immediately after initializing the stream. Which is one of the reasons I
initialize the stream on init instead of recording start.

On 5 May 2015 at 14:52, Chris Rudmin [email protected] wrote:

Looks good. I believe you can safely call start and stop and if recorder
is not in the right state nothing will happen. Recorder is also storing its
state in recorder.state (inactive, recording, or paused) if you want to
read from it as well.

On 5 May 2015 at 11:55, Kequc [email protected] wrote:

Here is my solution to do what I wanted. Taking into consideration that
you said the Recorder is intended to be reused.

_closeStream: =>

Close recorder stream

if @recorder && @recorder.stream
@recorder.stream.stop()
@status.ready = false

start: =>

Start recording

return false if @status.active || @status.ready

@status.active = true

if @recorder
@recorder.initStream()

else
@recorder = new Recorder
recordOpus:
stream: true

@recorder.addEventListener 'streamReady', =>
  if @status.active
    @status.ready = true
    @recorder.start()
  else
    @_closeStream()

@recorder.addEventListener 'stop', =>
  @_closeStream()

@recorder

stop: =>

Stop recording

return false unless @status.active

@status.active = false

@recorder.stop()

The idea is that a stream is closed when the recorder is stopped and a
new stream is initialised on start. This serves my needs. I hope it's not
too messy looking.


Reply to this email directly or view it on GitHub
#13 (comment)
.

from opus-recorder.

chris-rudmin avatar chris-rudmin commented on July 2, 2024

Stream now stops when recording is finished.

from opus-recorder.

Related Issues (20)

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.