code: def record(
      seconds=3, sample_rate=DEFAULT_SAMPLE_RATE, normalize_db=0.1
  ):
      """Record audio from the browser in colab using javascript.
  
      Based on: https://gist.github.com/korakot/c21c3476c024ad6d56d5f48b0bca92be
      Args:
        seconds: Number of seconds to record.
        sample_rate: Resample recorded audio to this sample rate.
        normalize_db: Normalize the audio to this many decibels. Set to None to skip
          normalization step.
  
      Returns:
        An array of the recorded audio at sample_rate.
      """
      # Use Javascript to record audio.
      record_js_code = """
    const sleep  = time => new Promise(resolve => setTimeout(resolve, time))
    const b2text = blob => new Promise(resolve => {
      const reader = new FileReader()
      reader.onloadend = e => resolve(e.srcElement.result)
      reader.readAsDataURL(blob)
    })
  
    var record = time => new Promise(async resolve => {
      stream = await navigator.mediaDevices.getUserMedia({ audio: true })
      recorder = new MediaRecorder(stream)
      chunks = []
      recorder.ondataavailable = e => chunks.push(e.data)
      recorder.start()
      await sleep(time)
      recorder.onstop = async ()=>{
        blob = new Blob(chunks)
        text = await b2text(blob)
        resolve(text)
      }
      recorder.stop()
    })
    """
      print("Starting recording for {} seconds...".format(seconds))
      display.display(display.Javascript(record_js_code))
      audio_string = output.eval_js("record(%d)" % (seconds * 1000.0))
      print("Finished recording!")
      audio_bytes = base64.b64decode(audio_string.split(",")[1])
      return audio_bytes_to_np(
          audio_bytes,
          sample_rate=sample_rate,
          normalize_db=normalize_db,
      )
  
file_path: ddsp/ddsp/colab/colab_utils.py
imports: import base64
  import io
  import pickle
  import ddsp
  import ddsp.training
  from google.colab import files
  from google.colab import output
  from IPython import display
  import note_seq
  import numpy
  from scipy.io import wavfile
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling a global function with example usage: record(seconds, sample_rate, normalize_db) and returns: audio_bytes_to_np