Unfortunately, there is no CurrentAudio[] function yet.

I'm trying to poll for 1 second clips of audio (as fast as possible) from my computer's microphone (and then continuously push them through a neural network I built).

Here's a simplified example of what I've tried:

net = NetInitialize @ NetChain[{
   "Input" -> {"Varying", 13},
   "Output" -> NetDecoder[{"Class", {"A", "B", "C"}}]]

inferAudio[] := 
    Module[{clip, enc = Values[AudioLocalMeasurements[#, "MFCC"]] &},
        clip = AudioCapture["Memory", MaxDuration -> 1, 
                    CaptureRunning -> True, SampleRate -> 16000];  
        net @ enc @ clip

$stop = False; t1 = Now; Button["Stop", $stop = True]
While[Refresh[$stop =!= True], t1 = Now; c = inferAudio[];
   t2 = Now; Print["Inferred class = ", c, ", delay = ", t2 - t1]]

This has a few problems:

  1. I'd like to remove the audio capturing GUI. There is no need for it and it slows everything down.
  2. The code is clunky and the delay between is a bit too much, also the front-end gets crashy.

I initially tried using ScheduledTask's but that was a terrible idea (doesn't play well with Dynamics). Don't run this, it will crash MMA:

recordings = {};
SessionSubmit @ ScheduledTask[
  AppendTo[recordings, AudioCapture[MaxDuration -> 1]], {1, 3}]

enter image description here

  • $\begingroup$ A good answer will help anyone who needs to live process audio from an input source. $\endgroup$ – M.R. Feb 18 '18 at 4:11

Here's a way to kill the GUI:

AudioCapture["UseGUI" -> False, MaxDuration -> 1]

I found this by digging. You can also use these:

Audio`CaptureDump`AudioCaptureHiddenOptions // Options

{"UseGUI" -> True, AudioDevice -> Automatic}

And then I can do things like:

 AudioCapture["UseGUI" -> False, MaxDuration -> 1],


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.