i am trying to make a spectrogram in matlab, here is my code:
% Record your voice for 100 seconds.
recObj = audiorecorder;
disp(\'Start speaking.\')
recordb
MATLAB is intrinsically single-threaded. Only one thing can happen at a time. This makes real time tasks somewhat difficult. As you noted, recordblocking does not return control to your script until those 100 seconds have elapsed. The key is in the word blocking.
The way around this is with callbacks and non-blocking functions. The audiorecorder object has a few methods and properties that enable this kind of behavior.
The audiorecorder properties:
- StartFcn: Set a function that will execute upon starting an asynchronous recording
- StopFcn: The function to be executed upon stopping a recording
- TimerFcn: The function to be executed every TimerPeriod seconds during a recording.
Then the record method will start the recording and process in the background, calling the above functions as directed.
By regularly updating your data in the callback function, you may update your plot. Unfortunately, this is similarly not trivial to do in an efficient manner that allows for live updates. But this should get you started.