I'm trying to save a recording using
AudioRecord. My recording gets overwritten even if I save the output in a fresh cell. This illustrates the issue:
astream = AudioStream[First@$AudioInputDevices]; sample = AudioRecord[astream]; DialogInput[Print["Record now for 5 s..."]; Pause; Print["Recorded ~ 5 s"]; DialogReturn["Close me"]]; AudioStop[astream]; player = Audio[sample]
My recording is returned as an output as shown. I save it to a new cell.
Now I do a new recording on the same channel:
AudioRecord[astream];(* once again *) DialogInput[Print["Record again now for 10 s..."]; Pause; Print["Recorded ~ 10 s"]; DialogReturn]; AudioStop[astream]; player
Now the recording above looks the same (this does not always happen though; sometimes a fresh audio gadget replaces the one I saved before) but the data has been overwritten with the first 5 s of the new recording.
This looks like a bug to me although I have an intuition as to why this is happening (
Dynamic); can anyone suggest a workaround?
A more fundamental issue is that it does not seem to be possible to close the audio stream or to dispose of the resources it is using (without quitting the kernel). That's what's familiar to me from using streams in other programming languages. Is it too much to hope this might be available in future?