stt.picovoice.hotword
Platypush documentation
stt.picovoice.hotword
- class platypush.plugins.stt.picovoice.hotword.SttPicovoiceHotwordPlugin(library_path: Optional[str] = None, model_file_path: Optional[str] = None, keyword_file_paths: Optional[List[str]] = None, sensitivity: float = 0.5, sensitivities: Optional[List[float]] = None, *args, **kwargs)[source]
Bases:
SttPlugin
This plugin performs hotword detection using PicoVoice.
Requires:
pvporcupine (
pip install pvporcupine
) for hotword detection.
- __init__(library_path: Optional[str] = None, model_file_path: Optional[str] = None, keyword_file_paths: Optional[List[str]] = None, sensitivity: float = 0.5, sensitivities: Optional[List[float]] = None, *args, **kwargs)[source]
- Parameters:
input_device – PortAudio device index or name that will be used for recording speech (default: default system audio input device).
hotword – When this word is detected, the plugin will trigger a
platypush.message.event.stt.HotwordDetectedEvent
instead of aplatypush.message.event.stt.SpeechDetectedEvent
event. You can use these events for hooking other assistants.hotwords – Use a list of hotwords instead of a single one.
conversation_timeout – If
hotword
orhotwords
are set andconversation_timeout
is set, the next speech detected event will trigger aplatypush.message.event.stt.ConversationDetectedEvent
instead of aplatypush.message.event.stt.SpeechDetectedEvent
event. You can hook custom hooks here to run any logic depending on the detected speech - it can emulate a kind of “OK, Google. Turn on the lights” interaction without using an external assistant (default: 10 seconds).block_duration – Duration of the acquired audio blocks (default: 1 second).
- convert_frames(frames: bytes) tuple [source]
Conversion method for raw audio frames. It just returns the input frames as bytes. Override it if required by your logic.
- Parameters:
frames – Input audio frames, as bytes.
- Returns:
The audio frames as passed on the input. Override if required.
- detect(audio_file: str) SpeechDetectedResponse [source]
Perform speech-to-text analysis on an audio file.
- Parameters:
audio_file – Path to the audio file.
- detect_speech(frames: tuple) str [source]
Method called within the
detection_thread
when new audio frames have been captured. Must be implemented by the derived classes.- Parameters:
frames – Audio frames, as returned by
convert_frames
.- Returns:
Detected text, as a string. Returns an empty string if no text has been detected.
- on_detection_ended() None [source]
Method called when the
detection_thread
stops. Clean up your context variables and models here.
- recording_thread(input_device: Optional[str] = None, *args, **kwargs) None [source]
Recording thread. It reads raw frames from the audio device and dispatches them to
detection_thread
.- Parameters:
block_duration – Audio blocks duration. Specify either
block_duration
orblock_size
.block_size – Size of the audio blocks. Specify either
block_duration
orblock_size
.input_device – Input device
- start_detection(*args, **kwargs) None [source]
Start the speech detection engine.
- Parameters:
input_device – Audio input device name/index override
seconds – If set, then the detection engine will stop after this many seconds, otherwise it’ll start running until
stop_detection
is called or application stop.block_duration –
block_duration
override.