Skip to content

Commit

Permalink
v2.0 flutter (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Nov 24, 2023
1 parent e2d4632 commit b38c7fd
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 221 deletions.
4 changes: 4 additions & 0 deletions binding/flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@

## [1.2.1] - 2023-08-25
* Native packages updated

## [2.0.0] - 2023-11-15
* Engine improvements
* Improved error reporting
2 changes: 1 addition & 1 deletion binding/flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Leopard is an on-device speech-to-text engine. Leopard is:
This binding is for running Leopard on **Flutter 2.8.1+** on the following platforms:

- Android 5.0+ (API 21+)
- iOS 11.0+
- iOS 13.0+

## Installation

Expand Down
10 changes: 8 additions & 2 deletions binding/flutter/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
group 'ai.picovoice.flutter.leopard'
version '1.2.1'
version '2.0.0'

buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1299/'
}
}

dependencies {
Expand All @@ -16,6 +19,9 @@ rootProject.allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1305/'
}
}
}

Expand All @@ -33,5 +39,5 @@ android {
}

dependencies {
implementation 'ai.picovoice:leopard-android:1.2.1'
implementation 'ai.picovoice:leopard-android:2.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
flutterContext = flutterPluginBinding.getApplicationContext();
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "leopard");
channel.setMethodCallHandler(this);

Leopard.setSdk("flutter");
}

@Override
Expand Down Expand Up @@ -90,11 +92,13 @@ private void leopardCreate(@NonNull MethodCall call, @NonNull Result result) {
String accessKey = call.argument("accessKey");
String modelPath = call.argument("modelPath");
boolean enableAutomaticPunctuation = call.argument("enableAutomaticPunctuation");
boolean enableDiarization = call.argument("enableDiarization");

Leopard.Builder leopardBuilder = new Leopard.Builder()
.setAccessKey(accessKey)
.setModelPath(modelPath)
.setEnableAutomaticPunctuation(enableAutomaticPunctuation);
.setEnableAutomaticPunctuation(enableAutomaticPunctuation)
.setEnableDiarization(enableDiarization);

Leopard leopard = leopardBuilder.build(flutterContext);
leopardPool.put(String.valueOf(System.identityHashCode(leopard)), leopard);
Expand Down Expand Up @@ -217,6 +221,7 @@ private Map<String, Object> leopardTranscriptToMap(LeopardTranscript result) {
wordMap.put("confidence", word.getConfidence());
wordMap.put("startSec", word.getStartSec());
wordMap.put("endSec", word.getEndSec());
wordMap.put("speakerTag", word.getSpeakerTag());
words.add(wordMap);
}
resultMap.put("words", words);
Expand Down
9 changes: 7 additions & 2 deletions binding/flutter/ios/Classes/SwiftLeopardPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Picovoice Inc.
// Copyright 2022-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
Expand Down Expand Up @@ -28,6 +28,8 @@ public class SwiftLeopardPlugin: NSObject, FlutterPlugin {

let methodChannel = FlutterMethodChannel(name: "leopard", binaryMessenger: registrar.messenger())
registrar.addMethodCallDelegate(instance, channel: methodChannel)

Leopard.setSdk(sdk: "flutter")
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand All @@ -44,11 +46,13 @@ public class SwiftLeopardPlugin: NSObject, FlutterPlugin {
if let accessKey = args["accessKey"] as? String,
let modelPath = args["modelPath"] as? String {
let enableAutomaticPunctuation = args["enableAutomaticPunctuation"] as? Bool
let enableDiarization = args["enableDiarization"] as? Bool

let leopard = try Leopard(
accessKey: accessKey,
modelPath: modelPath,
enableAutomaticPunctuation: enableAutomaticPunctuation ?? false
enableAutomaticPunctuation: enableAutomaticPunctuation ?? false,
enableDiarization: enableDiarization ?? false
)

let handle: String = String(describing: leopard)
Expand Down Expand Up @@ -137,6 +141,7 @@ public class SwiftLeopardPlugin: NSObject, FlutterPlugin {
wordMap["confidence"] = wordMeta.confidence
wordMap["startSec"] = wordMeta.startSec
wordMap["endSec"] = wordMeta.endSec
wordMap["speakerTag"] = wordMeta.speakerTag
wordMapArray.append(wordMap)
}
resultDictionary["words"] = wordMapArray
Expand Down
6 changes: 3 additions & 3 deletions binding/flutter/ios/leopard_flutter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'leopard_flutter'
s.version = '1.2.1'
s.version = '2.0.0'
s.summary = 'A Flutter package plugin for Picovoice\'s Leopard Speech-to-Text engine'
s.description = <<-DESC
A Flutter package plugin for Picovoice\'s Leopard Speech-to-Text engine
Expand All @@ -10,9 +10,9 @@ Pod::Spec.new do |s|
s.author = { 'Picovoice' => '[email protected]' }
s.source = { :git => "https://github.com/Picovoice/leopard.git" }
s.source_files = 'Classes/**/*'
s.platform = :ios, '11.0'
s.platform = :ios, '13.0'
s.dependency 'Flutter'
s.dependency 'Leopard-iOS', '~> 1.2.0'
s.dependency 'Leopard-iOS', '~> 2.0.0'

s.swift_version = '5.0'
end
20 changes: 16 additions & 4 deletions binding/flutter/lib/leopard.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Picovoice Inc.
// Copyright 2022-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
Expand Down Expand Up @@ -38,19 +38,27 @@ class Leopard {
///
/// [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
static Future<Leopard> create(String accessKey, String modelPath,
{enableAutomaticPunctuation = false}) async {
{
enableAutomaticPunctuation = false,
enableDiarization = false
}) async {
modelPath = await _tryExtractFlutterAsset(modelPath);

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

return Leopard._(
Expand Down Expand Up @@ -129,7 +137,11 @@ class Leopard {
List<LeopardWord> words = [];
for (dynamic word in result['words']) {
words.add(LeopardWord(
word['word'], word['startSec'], word['endSec'], word['confidence']));
word['word'],
word['startSec'],
word['endSec'],
word['confidence'],
word['speakerTag']));
}
return LeopardTranscript(transcript, words);
}
Expand Down
3 changes: 2 additions & 1 deletion binding/flutter/lib/leopard_transcript.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class LeopardWord {
final double startSec;
final double endSec;
final double confidence;
final int speakerTag;

LeopardWord(this._word, this.startSec, this.endSec, this.confidence);
LeopardWord(this._word, this.startSec, this.endSec, this.confidence, this.speakerTag);

String get word => _word ?? "";
}
2 changes: 1 addition & 1 deletion binding/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: leopard_flutter
description: A Flutter plugin for Picovoice's Leopard Speech-to-Text engine
version: 1.2.1
version: 2.0.0
homepage: https://picovoice.ai/
repository: https://github.com/Picovoice/leopard/
documentation: https://picovoice.ai/docs/leopard/
Expand Down
6 changes: 6 additions & 0 deletions demo/flutter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ buildscript {
repositories {
google()
jcenter()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1305/'
}
}

dependencies {
Expand All @@ -13,6 +16,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1305/'
}
}
}

Expand Down
Loading

0 comments on commit b38c7fd

Please sign in to comment.