Reputation: 4993
I am trying to do voice activity detection using webrtcvad 2.0.8. This https://pypi.python.org/pypi/webrtcvad provides the basic procedure. When I try to implement it as follows, I get an error. my code:
import webrtcvad
from scipy.io import wavfile
import scipy
source1 = path + "phone1.wav"
fs, audio = wavfile.read(source1)
audio_n = audio/float(2**15)
vad = webrtcvad.Vad(3)
def audioSlice(x, fs, framesz, hop):
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
X = scipy.array([x[i:i+framesamp] for i in range(0, len(x)-framesamp, hopsamp)])
return X
framesz=10./1000 #10 ms
hop = 1.0*framesz
Z = audioSlice(audio_n, fs, framesz, hop)
vad.is_speech(Z[100], fs)
The error that I get is:
is_speech(self, buf, sample_rate, length)
25 'buffer has %s frames, but length argument was %s' % (
26 int(len(buf) / 2.0), length))
---> 27 return _webrtcvad.process(self._vad, sample_rate, buf, length)
28
29
Error: Error while processing frame
Upvotes: 4
Views: 5804
Reputation: 25220
webrtcvad expects buffer to be a string with data bytes, not an array of floats. You can do something like
fr = np.int16(Z[100] * 32768).tobytes()
vad.is_speech(fr, fs)
Upvotes: 6