https://github.com/melizalab/py-ewave
Advantages:
Disadvantages:
Installation:
python3 -m pip install ewave
import ewave
with ewave.open('data/test_wav_pcm16.wav') as w:
print("samplerate = {0.sampling_rate} Hz, length = {0.nframes} samples, "
"channels = {0.nchannels}, dtype = {0.dtype!r}".format(w))
data = w.read()
data
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
plt.plot(data);
Obviously, the returned samples have the dtype
'int16'
(as stored in the file).
To be able to do something useful, we'll have to convert it to floating point and normalize it to a range from -1 to 1.
Luckily, there is a function especially made for this:
np.set_printoptions(precision=4)
ewave.rescale(data, 'float32')
Note: until version 1.0.4 this was broken, but now it works (see https://github.com/melizalab/py-ewave/issues/4).
Files with floating point data can be used, WAVEX is supported:
with ewave.open('data/test_wav_float32.wav') as w:
data = w.read()
plt.plot(data);
Looking good!
with ewave.open('data/test_wavex_pcm16.wav') as w:
data = w.read()
plt.plot(data);
with ewave.open('data/test_wavex_float32.wav') as w:
data = w.read()
plt.plot(data);
Opening a 24-bit PCM file fails with a not very verbose error message:
import traceback
try:
ewave.open('data/test_wav_pcm24.wav')
except:
traceback.print_exc()
else:
print("It works (unexpectedly)!")
# TODO!
print("ewave:", ewave.__version__)
import numpy, IPython, sys
print("NumPy: {}; IPython: {}".format(numpy.__version__, IPython.__version__))
print("Python interpreter:")
print(sys.version)