protected internal virtual SpeechClassifiedData classify(DoubleData audio) { double num = SpeechClassifier.logRootMeanSquare(audio.getValues()); this._isSpeech = false; if (num >= this.minSignal) { this.level = (this.level * (double)1f + num) / 2.0; if (num < this.background) { this.background = num; } else { this.background += (num - this.background) * this.adjustment; } if (this.level < this.background) { this.level = this.background; } this._isSpeech = (this.level - this.background > this.threshold); } SpeechClassifiedData speechClassifiedData = new SpeechClassifiedData(audio, this._isSpeech); if (this.logger.isLoggable(Level.FINEST)) { string text = ""; if (speechClassifiedData.isSpeech()) { text = "*"; } this.logger.finest(new StringBuilder().append("Bkg: ").append(this.background).append(", level: ").append(this.level).append(", current: ").append(num).append(' ').append(text).toString()); } this.collectStats(this._isSpeech); return(speechClassifiedData); }
public override Data getData() { while (this.outputQueue.isEmpty()) { Data data = this.getPredecessor().getData(); if (data == null) { break; } if (data is DataStartSignal) { this.reset(); this.outputQueue.add(data); break; } if (data is DataEndSignal) { if (this._inSpeech) { this.outputQueue.add(new SpeechEndSignal()); } this.outputQueue.add(data); break; } if (data is SpeechClassifiedData) { SpeechClassifiedData speechClassifiedData = (SpeechClassifiedData)data; if (speechClassifiedData.isSpeech()) { this.speechCount++; this.silenceCount = 0; } else { this.speechCount = 0; this.silenceCount++; } if (this._inSpeech) { this.outputQueue.add(data); } else { this.inputQueue.add(data); if (this.inputQueue.size() > this.startSpeechFrames + this.speechLeaderFrames) { this.inputQueue.remove(0); } } if (!this._inSpeech && this.speechCount == this.startSpeechFrames) { this._inSpeech = true; this.outputQueue.add(new SpeechStartSignal(speechClassifiedData.getCollectTime() - (long)this.speechLeader - (long)this.startSpeechFrames)); this.outputQueue.addAll(this.inputQueue.subList(Math.max(0, this.inputQueue.size() - this.startSpeechFrames - this.speechLeaderFrames), this.inputQueue.size())); this.inputQueue.clear(); } if (this._inSpeech && this.silenceCount == this.endSilenceFrames) { this._inSpeech = false; this.outputQueue.add(new SpeechEndSignal(speechClassifiedData.getCollectTime())); } } } if (!this.outputQueue.isEmpty()) { object obj = (Data)this.outputQueue.remove(0); if (((Data)obj) is SpeechClassifiedData) { SpeechClassifiedData speechClassifiedData = (SpeechClassifiedData)((Data)obj); obj = speechClassifiedData.getDoubleData(); } object obj2 = obj; Data result; if (obj2 != null) { if ((result = (obj2 as Data)) == null) { throw new IncompatibleClassChangeError(); } } else { result = null; } return(result); } return(null); }