create static method

Future<Leopard> create(
  1. String accessKey,
  2. String modelPath, {
  3. String? device,
  4. bool enableAutomaticPunctuation = false,
  5. bool enableDiarization = false,
})

Static creator for initializing Leopard

accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).

modelPath Path to the file containing model parameters.

device is the string representation of the device (e.g., CPU or GPU) to use. If set to best, the most suitable device is selected automatically. If set to gpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument to gpu:${GPU_INDEX}, where ${GPU_INDEX} is the index of the target GPU. If set to cpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument to cpu:${NUM_THREADS}, where ${NUM_THREADS} is the desired number of threads.

enableAutomaticPunctuation (Optional) Set to true to enable automatic punctuation insertion.

enableDiarization (Optional) Set to true to enable speaker diarization, which allows Leopard to differentiate speakers as part of the transcription process. Word metadata will include a speaker_tag to identify unique speakers.

Throws a LeopardException if not initialized correctly

returns an instance of the Leopard Speech-to-Text engine

Implementation

static Future<Leopard> create(
  String accessKey,
  String modelPath,
  {
    String? device,
    bool enableAutomaticPunctuation = false,
    bool enableDiarization = false
  }) async {
  modelPath = await _tryExtractFlutterAsset(modelPath);

  try {
    Map<String, dynamic> result = Map<String, dynamic>.from(
        await _channel.invokeMethod(_NativeFunctions.CREATE.name, {
      'accessKey': accessKey,
      'modelPath': modelPath,
      'device': device,
      'enableAutomaticPunctuation': enableAutomaticPunctuation,
      'enableDiarization': enableDiarization
    }));

    return Leopard._(
        result['handle'], result['sampleRate'], result['version']);
  } on PlatformException catch (error) {
    throw leopardStatusToException(error.code, error.message);
  } on Exception catch (error) {
    throw LeopardException(error.toString());
  }
}