Audio not saving in google colab # all imports
from IPython.display import Javascript
from google.colab import output
from base64 import b64decode


RECORD = &quot;&quot;&quot;
const sleep  = time =&gt; new Promise(resolve =&gt; setTimeout(resolve, time))
const b2text = blob =&gt; new Promise(resolve =&gt; {
  const reader = new FileReader()
  reader.onloadend = e =&gt; resolve(e.srcElement.result)
  reader.readAsDataURL(blob)
})
var record = time =&gt; new Promise(async resolve =&gt; {
  stream = await navigator.mediaDevices.getUserMedia({ audio: true })
  recorder = new MediaRecorder(stream)
  chunks = []
  recorder.ondataavailable = e =&gt; chunks.push(e.data)
  recorder.start()
  await sleep(time)
  recorder.onstop = async ()=&gt;{
    blob = new Blob(chunks)
    text = await b2text(blob)
    resolve(text)
  }
  recorder.stop()
})
&quot;&quot;&quot;

def record(sec=5):
  display(Javascript(RECORD))
  s = output.eval_js('record(%d)' % (sec*1000))
  b = b64decode(s.split(',')[1])
  with open('audio.wav','wb') as f:
    f.write(b)
  return 'audio.wav'  # or webm ?


The above is the code for audio recording in google colab. But the audio file is not saved in google colab and showing after running the code. kindly help?
You are only defining the record function but never actually running it. Adding record() to the end of the code works for me in Google Colab and saves the audio to the audio.wav file.