karen.devices.Listener

Listener device to capture audio from microphone and convert any speech to text and send to callback method.

__init__(self, parent=None, speechModel=None, speechScorer=None, audioChannels=1, audioSampleRate=16000, vadAggressiveness=1, speechRatio=0.75, speechBufferSize=50, speechBufferPadding=350, audioDeviceIndex=None, callback=None) special

Listener Initialization

Parameters:
  • parent (object) – Containing object's reference. Normally this would be the device container. (optional)

  • speechModel (str) – Path and filename of Deepspeech Speech Model file. If not set then listener will do a basic seach for the PBMM or TFLite file.

  • speechScorer (str) – Path and filename of Deepspeech Scorer file. Okay for this to be None as scorer file is not required.

  • audioChannels (int) – Audio channels for audio source. VAD requires this to be 1 channel.

  • audioSampleRate (int) – Audio sample rate of audio source. VAD requires this to be 16000.

  • vadAggressiveness (int) – Voice Activity Detection (VAD) aggressiveness for filtering noise. Accepts 1 thru 3.

  • speechRatio (float) – Must be between 0 and 1 as a decimal

  • speechBufferSize (int) – Buffer size for speech frames

  • speechBufferPadding (int) – Padding, in milliseconds, of speech frames

  • audioDeviceIndex (int) – Listening device index number. If not set then will use default audio capture device.

  • callback (function) – Callback function for which to send capture text

audioOutEnd(self, httpRequest=None)

Sets the device to start capturing audio again after an audioOutStart message.

Parameters:
  • httpRequest (KHTTPHandler) – Handler for inbound request. Not used.

Returns:
  • (bool) – True on success else will raise an exception.

audioOutStart(self, httpRequest=None)

Sets the device to temporarily stop capturing audio (used to prevent listening to the speaker device output).

Parameters:
  • httpRequest (KHTTPHandler) – Handler for inbound request. Not used.

Returns:
  • (bool) – True on success else will raise an exception.

isRunning(self)

Identifies if the device is actively running.

Returns:
  • (bool) – True if running; False if not running.

start(self, httpRequest=None, useThreads=True)

Starts the listener to listen to the default audio device

Parameters:
  • httpRequest (KHTTPHandler) – Handler for inbound request. Not used.

  • useThreads (bool) – Indicates if the brain should be started on a new thread.

Returns:
  • (bool) – True on success else will raise an exception.

stop(self, httpRequest=None)

Stops the listener and any active audio streams

Parameters:
  • httpRequest (KHTTPHandler) – Handler for inbound request. Not used.

Returns:
  • (bool) – True on success else will raise an exception.

wait(self, seconds=0)

Waits for any active listeners to complete before closing

Parameters:
  • seconds (int) – Number of seconds to wait before calling the "stop()" function

Returns:
  • (bool) – True on success else will raise an exception.