Recorder

[1]:
import sc3nb as scn
[2]:
sc = scn.startup()
Starting sclang process... Done.
Registering OSC /return callback in sclang... Done.
Loading default sc3nb SynthDefs... Done.
Booting SuperCollider Server... Done.
[3]:
help(scn.Recorder)
Help on class Recorder in module sc3nb.sc_objects.recorder:

class Recorder(builtins.object)
 |  Recorder(path: str = 'record.wav', nr_channels: int = 2, rec_header: str = 'wav', rec_format: str = 'int16', bufsize: int = 65536, server: Union[sc3nb.sc_objects.server.SCServer, NoneType] = None)
 |
 |  Allows to record audio easily.
 |
 |  Methods defined here:
 |
 |  __del__(self)
 |
 |  __init__(self, path: str = 'record.wav', nr_channels: int = 2, rec_header: str = 'wav', rec_format: str = 'int16', bufsize: int = 65536, server: Union[sc3nb.sc_objects.server.SCServer, NoneType] = None)
 |      Create and prepare a recorder.
 |
 |      Parameters
 |      ----------
 |      path : str, optional
 |          path of recording file, by default "record.wav"
 |      nr_channels : int, optional
 |          Number of channels, by default 2
 |      rec_header : str, optional
 |          File format, by default "wav"
 |      rec_format : str, optional
 |          Recording resolution, by default "int16"
 |      bufsize : int, optional
 |          size of buffer, by default 65536
 |      server : SCServer, optional
 |          server used for recording,
 |          by default use the SC default server
 |
 |  __repr__(self) -> str
 |      Return repr(self).
 |
 |  pause(self, timetag: float = 0)
 |      Pause the recording.
 |
 |      Parameters
 |      ----------
 |      timetag : float, by default 0 (immediately)
 |          Time (or time offset when <1e6) to pause
 |
 |      Raises
 |      ------
 |      RuntimeError
 |          When trying to pause if not recording.
 |
 |  prepare(self, path: str = 'record.wav', nr_channels: int = 2, rec_header: str = 'wav', rec_format: str = 'int16', bufsize: int = 65536)
 |      Pepare the recorder.
 |
 |      Parameters
 |      ----------
 |      path : str, optional
 |          path of recording file, by default "record.wav"
 |      nr_channels : int, optional
 |          Number of channels, by default 2
 |      rec_header : str, optional
 |          File format, by default "wav"
 |      rec_format : str, optional
 |          Recording resolution, by default "int16"
 |      bufsize : int, optional
 |          size of buffer, by default 65536
 |
 |      Raises
 |      ------
 |      RuntimeError
 |          When Recorder does not needs to be prepared.
 |
 |  resume(self, timetag: float = 0)
 |      Resume the recording
 |
 |      Parameters
 |      ----------
 |      timetag : float, by default 0 (immediately)
 |          Time (or time offset when <1e6) to resume
 |
 |      Raises
 |      ------
 |      RuntimeError
 |          When trying to resume if not paused.
 |
 |  start(self, timetag: float = 0, duration: Union[float, NoneType] = None, node: Union[sc3nb.sc_objects.node.Node, int] = 0, bus: int = 0)
 |      Start the recording.
 |
 |      Parameters
 |      ----------
 |      timetag : float, by default 0 (immediately)
 |          Time (or time offset when <1e6) to start
 |      duration : float, optional
 |          Length of the recording, by default until stopped.
 |      node : Union[Node, int], optional
 |          Node that should be recorded, by default 0
 |      bus : int, by default 0
 |          Bus that should be recorded
 |
 |      Raises
 |      ------
 |      RuntimeError
 |          When trying to start a recording unprepared.
 |
 |  stop(self, timetag: float = 0)
 |      Stop the recording.
 |
 |      Parameters
 |      ----------
 |      timetag : float, by default 0 (immediately)
 |          Time (or time offset when <1e6) to stop
 |
 |      Raises
 |      ------
 |      RuntimeError
 |          When trying to stop if not started.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

Recording sound into a file

[4]:
# use the Recording class to capture the output
recorder = scn.Recorder(path="my_record.wav")

with sc.server.bundler() as bundler:
    recorder.start(0.1)
    # /s_new synth name, node id, add action (0 to head), target (1 default group), synth arguments...
    scn.Synth("s1", {"freq": 200, "dur": 1})
    bundler.wait(0.3)
    scn.Synth("s1", {"freq": 300, "dur": 1})
    recorder.stop(1.5)
  • note that the sorting in scsynth node tree is with ‘at begin’ rule

  • otherwise the rendered tones would be rendered after the outbus was written to file resulting in an empty file.

  • the file is located in the same folder as this .ipynb file.

[5]:
sc.exit()
Quitting SCServer... Done.
Exiting sclang... Done.
[ ]: