Warning: session_start(): open(/var/lib/php/sessions/sess_sq7371di9iviot6rjnlscr2qs1, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
// Note: This is dependent on input buffer size which is not optimal.
// Tested with buffer size 232 ms (using CD quality)
cmodule VAD > DynPrintLogAndEnabled {
switchable double windowSize = 1; // milliseconds
switchable double threshold =
// 10.0; // the magic value for 44 KHz stereo
1; // for 8 KHz mono
transient double confidence;
start {
printLogUpdateInterval = 100;
// technically we are treating stereo input as mono samples
// but it might not matter
dm_addAudioListener(voidfunc(short[] data) enter {
if (!enabled) ret;
short[] buffer = cloneArray(data);
dm_q(r {
if (q.size() > 2) ret with print("overload");
short[] buf = buffer;
//printStruct(takeFirstOfShortArray(8, buf));
float sampleRate = dm_audioInputSampleRate();
if (sampleRate == 0) ret;
float originalSampleRate = sampleRate;
int channels = dm_audioInputChannels();
if (channels > 1) buf = mixStereoShortArrayToMono(buf);
buf = convertSampleRate_shortArray_simple(buf, sampleRate, 8000);
sampleRate = 8000f;
long time = sysNow();
int windowLength = msToSamples_int(windowSize, sampleRate);
//printWithMilliseconds("Window length (" + sampleRate + "): " + windowLength);
new L l;
L chunks = intRangeChunks(buf, windowLength);
for (IntRange r : chunks)
l.add(normalizedAutocorrelationOfAudioSamples(buf, r));
// print one table for reference
print(asList(normalizedAutocorrelationTableForAudioSamples(buf, first(chunks))));
double result = doubleAverage(l);
confidence = result/threshold*50;
int vol = shortAbsMax(buf);
print("VAD " + (confidence >= 50 ? "XXX" : " ") + " value: " + iround(confidence) + " % [" + elapsedMS(time) + " ms, "
+ nWindows(l(buf)/windowLength) + " of size " + windowLength + ", converted from \*originalSampleRate*/ Hz, " + nChannels(channels) + ", volume: " + iround(vol/32767.0*100) + "]");
});
});
}
// API
bool hasVoiceActivity() {
ret confidence >= 50;
}
}