_setIsMicQuiet()

in lex-web-ui/src/lib/lex/recorder.js [385:424]


  _setIsMicQuiet() {
    const now = this._audioContext.currentTime;

    const isMicQuiet = (this._maxVolume < this.volumeThreshold ||
      this._slow < this.quietThreshold);

    // start record the time when the line goes quiet
    // fire event
    if (!this._isMicQuiet && isMicQuiet) {
      this._quietStartTime = this._audioContext.currentTime;
      this._eventTarget.dispatchEvent(new Event('quiet'));
    }
    // reset quiet timer when there's enough sound
    if (this._isMicQuiet && !isMicQuiet) {
      this._quietStartTime = 0;
      this._eventTarget.dispatchEvent(new Event('unquiet'));
    }
    this._isMicQuiet = isMicQuiet;

    // if autoincrease is enabled, exponentially increase the mimimun recording
    // time based on consecutive silent recordings
    const recordingTimeMin =
      (this.recordingTimeMinAutoIncrease) ?
        (this.recordingTimeMin - 1) +
        (this.recordingTimeMax **
         (1 - (1 / (this._silentRecordingConsecutiveCount + 1)))) :
        this.recordingTimeMin;

    // detect voice pause and stop recording
    if (this.autoStopRecording &&
      this._isMicQuiet && this._state === 'recording' &&
      // have I been recording longer than the minimum recording time?
      now - this._recordingStartTime > recordingTimeMin &&
      // has the slow sample value been below the quiet threshold longer than
      // the minimum allowed quiet time?
      now - this._quietStartTime > this.quietTimeMin
    ) {
      this.stop();
    }
  }