5
$\begingroup$

How do I measure the sample rate of an imported file in Mathematica?

I imported the WAV file:

solo = Import["solo.wav"]

When I wrote:

SampleRate[solo] 

I received: Sound

But I just need a number like 28.000 to be returned.

$\endgroup$
9
$\begingroup$
solo = Import[ "ExampleData/rule30.wav" ]

Mathematica graphics

Cases[solo, (SampledSoundFunction | SampledSoundList)[__, r_] :>  r, Infinity][[1]]

44100

| improve this answer | |
$\endgroup$
12
$\begingroup$

One can also use Import[] to directly query the *.wav file's sample rate, like so:

Import["ExampleData/rule30.wav", "SampleRate"]
   44100
| improve this answer | |
$\endgroup$
6
$\begingroup$

The sample rate is the second element in solo. The first element (i.e., solo[[1, 1]]) is the waveform data.

solo = Import["ExampleData/rule30.wav"];
solo[[1, 2]]

44100
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Doesn't work on new Mathematica 11.2 $\endgroup$ – Miladiouss Dec 20 '17 at 6:26
2
$\begingroup$

For Mathematica 11:

AudioSampleRate[myAudio]
| improve this answer | |
$\endgroup$
0
$\begingroup$
QuantityMagnitude@AudioSampleRate@Audio@solo
(*44100*)
| improve this answer | |
$\endgroup$
  • $\begingroup$ This doesn't work $\endgroup$ – Miladiouss Dec 20 '17 at 6:24

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.