Muhammad Ikhwan Perwira
Muhammad Ikhwan Perwira

Reputation: 1032

scipy.io.wavfile.read return explanation

I know I can read it at https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html, but I'm too stupid to understand it.

from scipy.io.wavfile import read
sample_rate, data = read("./drive/MyDrive/PSD.wav")
print(len(data))
print(data)

What representation of length array of data? I have output 1500000 but what does it mean or what unit it used? And sample_rate is 488000, I think I understand about it but I'm not sure.

And when I printed the data it gave me output

[[  0   0]
 [  0   0]
 [  0   0]
 ...
 [-25 -25]
 [ 18  18]
 [ -4  -4]]

I know it has left channel and right channel, but what is amplitude units?

Upvotes: 0

Views: 506

Answers (1)

Bob
Bob

Reputation: 14654

If you have a two columns arrays it means your wave file has two channels (stereo, left/right). The sample rate gives the number of samples per second, so the sampling period is (1 / sample_rate).

You could plot it as well

import matplotlib.pyplot as plt
import numpy as np
# time for each sample
t = np.arange(len(data)) / sample_rate
plt.subplot(211)
plt.plot(t, data[:,0]);
plt.subplot(212)
plt.plot(t, data[:,1]);

Upvotes: 1

Related Questions