0
$\begingroup$
AudioPlot[Audio[File["Downloads/1_mp3.wav"]]]
data = Cases[AudioPlot[Audio[File["Downloads/1_mp3.wav"]]], Line[x_] :> x, Infinity]

This code can extract data points at seemingly random interval from a sound wave.

enter image description here

However, how do I extract points at a fixed interval of x, say 0.001?

$\endgroup$
0
$\begingroup$

The easiest way that I'm aware of would be to use AudioData[] and pick every nth value.

audio = Audio[File["Downloads/1_mp3.wav"]];
sRate = Options[audio, SampleRate];
spacing = N[1/sRate]

The output of this first part is going to tell us the time between data points based on the sample rate of the audio file. In the case of the file I was testing, the sample rate was 22050 s$^{-1}$, which means data are 0.0000453515 s apart. You can choose any integer multiple of this that you like. In your example of 0.001 s, $0.001 \textrm{ s }\cdot\ 22050 \textrm{ Hz } = 22.05$. Therefore, the nearest integer is 22.

(* The [[1]] after AudioData[audio] selects out only the first channel. 
   If your data has more than one channel, you may not
   want to do that. *)
data = AudioData[audio][[1]]; 
timing = 0.001;
selector = Round[timing/sRate];
selectData = data[[;; ;; selector]]

This isn't the most elegant code, and could certainly be tidied up depending on what exactly you want to do with the data, but hopefully this will get you started!

| improve this answer | |
$\endgroup$

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.