Skip to content
Advertisement

Google colab audio recording, how to implement a more precise way to tell users to start speaking into mic

I am trying to create a program that will record audio for a machine learning project, and I want to use google colab so that people don’t have to install or run anything on their system, I found this example online that records and plays audio:

cell 1 contains the js code to record audio and the python code to turn it into a bytes object:

JavaScript

cell 2 runs the recording functions:

JavaScript

cell 3 creates a display item so you can play the recording:

JavaScript

In the end I will be having users speak a word for 1 second, and the issue I am running into is that there is a discrepancy between when the user is told to speak and when the actual recording starts, if I speak right away the beginning of my speaking is not in the audio file. Is there a way to more precisely line up when the command to speak appears and when the actual recording starts?

Advertisement

Answer

I think the discrepancy is because of the time needed to set things up. In particular, the time to run the following codes before we could get to recorder.start()

JavaScript

Also, when print("Speak Now...") is executed, it should be quickly followed by recorder.start().

So I think we can reduce the delay by setting things up in advance and just: print(“Speak Now…”); recorder.start()

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement