Skip to content

Commit

Permalink
Flutter updates (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Feb 9, 2024
1 parent c0b201d commit 7872c84
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 95 deletions.
3 changes: 3 additions & 0 deletions binding/flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@

## [2.0.1] - 2023-11-30
* Update native packages

## [2.0.2] - 2024-02-08
* Additional gradle plugin build support
15 changes: 13 additions & 2 deletions binding/flutter/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'ai.picovoice.flutter.leopard'
version '2.0.1'
version '2.0.2'

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

Expand All @@ -22,6 +22,17 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
namespace "ai.picovoice.flutter.leopard"
}

if (agpVersion.tokenize('.')[0].toInteger() >= 8) {
buildFeatures {
buildConfig = true
}
}

compileSdkVersion 31

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 16 13:19:26 PST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022-2023 Picovoice Inc.
Copyright 2022-2024 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 @@ -52,7 +52,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
Method method;
try {
method = Method.valueOf(call.method.toUpperCase());
method = Method.valueOf(call.method);
} catch (IllegalArgumentException e) {
result.error(
LeopardRuntimeException.class.getSimpleName(),
Expand Down
4 changes: 2 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-2023 Picovoice Inc.
// Copyright 2022-2024 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 @@ -33,7 +33,7 @@ public class SwiftLeopardPlugin: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
guard let method = Method(rawValue: call.method.uppercased()) else {
guard let method = Method(rawValue: call.method) else {
result(errorToFlutterError(
LeopardRuntimeError("Leopard method '\(call.method)' is not a valid function")))
return
Expand Down
2 changes: 1 addition & 1 deletion 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 = '2.0.1'
s.version = '2.0.2'
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 Down
41 changes: 24 additions & 17 deletions binding/flutter/lib/leopard.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022-2023 Picovoice Inc.
// Copyright 2022-2024 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 All @@ -17,6 +17,17 @@ import 'package:leopard_flutter/leopard_transcript.dart';
import 'package:path_provider/path_provider.dart';
import 'package:leopard_flutter/leopard_error.dart';

enum _NativeFunctions {
// ignore:constant_identifier_names
CREATE,
// ignore:constant_identifier_names
PROCESS,
// ignore:constant_identifier_names
PROCESSFILE,
// ignore:constant_identifier_names
DELETE
}

class Leopard {
static final MethodChannel _channel = MethodChannel("leopard");

Expand All @@ -41,20 +52,17 @@ class Leopard {
/// [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,
enableDiarization = false
}) async {
{enableAutomaticPunctuation = false, enableDiarization = false}) async {
modelPath = await _tryExtractFlutterAsset(modelPath);

try {
Map<String, dynamic> result =
Map<String, dynamic>.from(await _channel.invokeMethod('create', {
Map<String, dynamic> result = Map<String, dynamic>.from(
await _channel.invokeMethod(_NativeFunctions.CREATE.name, {
'accessKey': accessKey,
'modelPath': modelPath,
'enableAutomaticPunctuation': enableAutomaticPunctuation,
Expand All @@ -81,7 +89,8 @@ class Leopard {
Future<LeopardTranscript> process(List<int>? frame) async {
try {
Map<String, dynamic> result = Map<String, dynamic>.from(await _channel
.invokeMethod('process', {'handle': _handle, 'frame': frame}));
.invokeMethod(_NativeFunctions.PROCESS.name,
{'handle': _handle, 'frame': frame}));

return _pluginResultToLeopardTranscript(result);
} on PlatformException catch (error) {
Expand All @@ -100,7 +109,8 @@ class Leopard {
Future<LeopardTranscript> processFile(String path) async {
try {
Map<String, dynamic> result = Map<String, dynamic>.from(await _channel
.invokeMethod('processfile', {'handle': _handle, 'path': path}));
.invokeMethod(_NativeFunctions.PROCESSFILE.name,
{'handle': _handle, 'path': path}));

return _pluginResultToLeopardTranscript(result);
} on PlatformException catch (error) {
Expand All @@ -113,7 +123,8 @@ class Leopard {
/// Frees memory that was allocated for Leopard
Future<void> delete() async {
if (_handle != null) {
await _channel.invokeMethod('delete', {'handle': _handle});
await _channel
.invokeMethod(_NativeFunctions.DELETE.name, {'handle': _handle});
_handle = null;
}
}
Expand All @@ -136,12 +147,8 @@ class Leopard {

List<LeopardWord> words = [];
for (dynamic word in result['words']) {
words.add(LeopardWord(
word['word'],
word['startSec'],
word['endSec'],
word['confidence'],
word['speakerTag']));
words.add(LeopardWord(word['word'], word['startSec'], word['endSec'],
word['confidence'], word['speakerTag']));
}
return LeopardTranscript(transcript, words);
}
Expand Down
Loading

0 comments on commit 7872c84

Please sign in to comment.