/// <summary> /// Picovoice constructor /// </summary> /// <param name="keywordPath">Absolute path to Porcupine's keyword model file.</param> /// <param name="wakeWordCallback"> /// User-defined callback invoked upon detection of the wake phrase. /// The callback accepts no input arguments. /// </param> /// <param name="contextPath"> /// Absolute path to file containing context parameters. A context represents the set of /// expressions(spoken commands), intents, and intent arguments(slots) within a domain of interest. /// </param> /// <param name="inferenceCallback"> /// User-defined callback invoked upon completion of intent inference. The callback /// accepts a single input argument of type `Map<String, dynamic>` that is populated with the following items: /// (1) IsUnderstood: whether Rhino understood what it heard based on the context /// (2) Intent: if isUnderstood, name of intent that were inferred /// (3) Slots: if isUnderstood, dictionary of slot keys and values that were inferred /// </param> /// <param name="porcupineModelPath">Absolute path to the file containing Porcupine's model parameters.</param> /// <param name="porcupineSensitivity"> /// Wake word detection sensitivity. It should be a number within [0, 1]. A higher /// sensitivity results in fewer misses at the cost of increasing the false alarm rate. /// </param> /// <param name="rhinoModelPath">Absolute path to the file containing Rhino's model parameters.</param> /// <param name="rhinoSensitivity"> /// Inference sensitivity. It should be a number within [0, 1]. A higher sensitivity value /// results in fewer misses at the cost of(potentially) increasing the erroneous inference rate. /// </returns> public static Picovoice Create(string keywordPath, Action wakeWordCallback, string contextPath, Action <Inference> inferenceCallback, string porcupineModelPath = null, float porcupineSensitivity = 0.5f, string rhinoModelPath = null, float rhinoSensitivity = 0.5f) { Porcupine porcupine = Porcupine.Create(keywordPaths: new List <string> { keywordPath }, modelPath: porcupineModelPath, sensitivities: new List <float> { porcupineSensitivity }); Rhino rhino = Rhino.Create(contextPath: contextPath, modelPath: rhinoModelPath, sensitivity: rhinoSensitivity); if (porcupine.FrameLength != rhino.FrameLength) { throw new ArgumentException("Porcupine and Rhino frame lengths are different"); } if (porcupine.SampleRate != rhino.SampleRate) { throw new ArgumentException("Porcupine and Rhino sample rate are different"); } return(new Picovoice(porcupine, wakeWordCallback, rhino, inferenceCallback)); }
/// <summary> /// Creates an instance of the Porcupine wake word engine from custom keyword files. /// </summary> /// <param name="keywordPaths">List of absolute paths to keyword model files (.ppn).</param> /// <param name="wakeWordCallback">A callback that is triggered when one of the given keywords has been detected by Porcupine.</param> /// <param name="modelPath">(Optional) Absolute path to the file containing model parameters. If not set it will be set to the default location.</param> /// <param name="sensitivities"> /// (Optional) Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer /// misses at the cost of increasing the false alarm rate. If not set 0.5 will be used. /// </param> /// <param name="errorCallback">(Optional) Callback that triggers is the engine experiences a problem while processing audio.</param> /// <returns>An instance of PorcupineManager.</returns> public static PorcupineManager FromKeywordPaths(IEnumerable <string> keywordPaths, Action <int> wakeWordCallback, string modelPath = null, IEnumerable <float> sensitivities = null, Action <Exception> errorCallback = null) { Porcupine porcupine = Porcupine.Create(keywordPaths: keywordPaths, modelPath: modelPath, sensitivities: sensitivities); return(new PorcupineManager(porcupine, wakeWordCallback, errorCallback)); }
/// <summary> /// Creates an instance of the Porcupine wake word engine from custom keyword files. /// </summary> /// <param name="accessKey">AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)</param> /// <param name="keywordPaths">List of absolute paths to keyword model files (.ppn).</param> /// <param name="wakeWordCallback">A callback that is triggered when one of the given keywords has been detected by Porcupine.</param> /// <param name="modelPath">(Optional) Absolute path to the file containing model parameters. If not set it will be set to the default location.</param> /// <param name="sensitivities"> /// (Optional) Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer /// misses at the cost of increasing the false alarm rate. If not set 0.5 will be used. /// </param> /// <param name="processErrorCallback">(Optional) Callback that triggers is the engine experiences a problem while processing audio.</param> /// <returns>An instance of PorcupineManager.</returns> public static PorcupineManager FromKeywordPaths(string accessKey, IEnumerable <string> keywordPaths, Action <int> wakeWordCallback, string modelPath = null, IEnumerable <float> sensitivities = null, Action <PorcupineException> processErrorCallback = null) { Porcupine porcupine = Porcupine.FromKeywordPaths(accessKey: accessKey, keywordPaths: keywordPaths, modelPath: modelPath, sensitivities: sensitivities); return(new PorcupineManager(porcupine, wakeWordCallback, processErrorCallback)); }
// private constructor private PorcupineManager(Porcupine porcupine, Action <int> wakeWordCallback, Action <Exception> errorCallback = null) { _porcupine = porcupine; _wakeWordCallback = wakeWordCallback; _errorCallback = errorCallback; _voiceProcessor = VoiceProcessor.Instance; _voiceProcessor.OnFrameCaptured += OnFrameCaptured; }
// private constructor private Picovoice(Porcupine porcupine, Action wakeWordCallback, Rhino rhino, Action <Inference> inferenceCallback) { _porcupine = porcupine; _wakeWordCallback = wakeWordCallback; _rhino = rhino; _inferenceCallback = inferenceCallback; FrameLength = porcupine.FrameLength; SampleRate = porcupine.SampleRate; PorcupineVersion = porcupine.Version; RhinoVersion = rhino.Version; ContextInfo = rhino.ContextInfo; }
/// <summary> /// Frees memory that was allocated for Picovoice /// </summary> public void Dispose() { if (_porcupine != null) { _porcupine.Dispose(); _porcupine = null; } if (_rhino != null) { _rhino.Dispose(); _rhino = null; } }
/// <summary> /// Free resources that were allocated to Porcupine and the voice processor /// </summary> public void Delete() { if (_voiceProcessor != null) { if (_voiceProcessor.IsRecording) { _voiceProcessor.StopRecording(); } _voiceProcessor.OnFrameCaptured -= OnFrameCaptured; _voiceProcessor = null; } if (_porcupine != null) { _porcupine.Dispose(); _porcupine = null; } }