Skip to content

Commit

Permalink
v2.0 rn (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Nov 24, 2023
1 parent b38c7fd commit e7d4519
Show file tree
Hide file tree
Showing 29 changed files with 2,687 additions and 3,093 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/react-native-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ jobs:

- name: Pre-build dependencies
run: npm install yarn

# ************ REMOVE AFTER RELEASE *****************
- name: Build and package binding
working-directory: binding/react-native
run: yarn && yarn pkg

- name: Add to demo
run: yarn add ../../binding/react-native/pkg/picovoice-leopard-react-native-2.0.0.tgz
# ***************************************************

- name: Install dependencies
run: yarn android-install
Expand Down Expand Up @@ -65,6 +74,15 @@ jobs:

- name: Pre-build dependencies
run: npm install yarn

# ************ REMOVE AFTER RELEASE *****************
- name: Build and package binding
working-directory: binding/react-native
run: yarn && yarn pkg

- name: Add to demo
run: yarn add ../../binding/react-native/pkg/picovoice-leopard-react-native-2.0.0.tgz
# ***************************************************

- name: Install dependencies
run: yarn ios-install
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/react-native-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ jobs:
run: |
yarn install
./copy_test_resources.sh
- name: Cocoapods install
working-directory: binding/react-native/test-app/LeopardTestApp/ios
run: pod install
run: pod install --repo-update

- name: Inject AppID
run: sed -i '.bak' 's:{TESTING_ACCESS_KEY_HERE}:${{secrets.PV_VALID_ACCESS_KEY}}:' Tests.ts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -44,4 +44,4 @@ jobs:
run: yarn install

- name: Build
run: yarn
run: yarn prepare
5 changes: 4 additions & 1 deletion binding/react-native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1305'
}
}

dependencies {
Expand Down Expand Up @@ -118,5 +121,5 @@ repositories {
dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
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 @@ -38,6 +38,8 @@ public class LeopardModule extends ReactContextBaseJavaModule {
public LeopardModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;

Leopard.setSdk("react-native");
}

@Override
Expand All @@ -50,13 +52,15 @@ public void create(
String accessKey,
String modelPath,
boolean enableAutomaticPunctuation,
boolean enableDiarization,
Promise promise) {
try {

Leopard leopard = new Leopard.Builder()
.setAccessKey(accessKey)
.setModelPath(modelPath.isEmpty() ? null : modelPath)
.setEnableAutomaticPunctuation(enableAutomaticPunctuation)
.setEnableDiarization(enableDiarization)
.build(reactContext);
leopardPool.put(String.valueOf(System.identityHashCode(leopard)), leopard);

Expand Down Expand Up @@ -146,6 +150,7 @@ private WritableMap leopardTranscriptToWriteableMap(LeopardTranscript result) {
wordMap.putDouble("confidence", word.getConfidence());
wordMap.putDouble("startSec", word.getStartSec());
wordMap.putDouble("endSec", word.getEndSec());
wordMap.putInt("speakerTag", word.getSpeakerTag());
words.pushMap(wordMap);
}
resultMap.putArray("words", words);
Expand Down
1 change: 1 addition & 0 deletions binding/react-native/ios/Leopard.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface RCT_EXTERN_MODULE(PvLeopard, NSObject)
RCT_EXTERN_METHOD(create: (NSString *)accessKey
modelPath: (NSString *)modelPath
enableAutomaticPunctuation: (BOOL)enableAutomaticPunctuation
enableDiarization: (BOOL)enableDiarization
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject)

Expand Down
14 changes: 11 additions & 3 deletions binding/react-native/ios/Leopard.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 All @@ -15,19 +15,26 @@ import Leopard
class PvLeopard: NSObject {
private var leopardPool: [String: Leopard] = [:]

@objc(create:modelPath:enableAutomaticPunctuation:resolver:rejecter:)
override init() {
super.init()
Leopard.setSdk(sdk: "react-native")
}

@objc(create:modelPath:enableAutomaticPunctuation:enableDiarization:resolver:rejecter:)
func create(
accessKey: String,
modelPath: String,
enableAutomaticPunctuation: Bool,
enableDiarization: Bool,
resolver resolve: RCTPromiseResolveBlock,
rejecter reject: RCTPromiseRejectBlock) {

do {
let leopard = try Leopard(
accessKey: accessKey,
modelPath: modelPath,
enableAutomaticPunctuation: enableAutomaticPunctuation
enableAutomaticPunctuation: enableAutomaticPunctuation,
enableDiarization: enableDiarization
)

let handle: String = String(describing: leopard)
Expand Down Expand Up @@ -120,6 +127,7 @@ class PvLeopard: NSObject {
wordMap["confidence"] = wordMeta.confidence
wordMap["startSec"] = wordMeta.startSec
wordMap["endSec"] = wordMeta.endSec
wordMap["speakerTag"] = wordMeta.speakerTag
wordMapArray.append(wordMap)
}
resultMap["words"] = wordMapArray
Expand Down
4 changes: 2 additions & 2 deletions binding/react-native/leopard-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "11.0" }
s.platforms = { :ios => "13.0" }
s.source = { :git => "https://github.com/Picovoice/leopard.git", :tag => "#{s.version}" }

s.source_files = "ios/*.{h,m,mm,swift}"

s.dependency "React"
s.dependency "Leopard-iOS", '~> 1.2.0'
s.dependency "Leopard-iOS", '~> 2.0.0'
end
2 changes: 1 addition & 1 deletion binding/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/leopard-react-native",
"version": "1.2.1",
"version": "2.0.0",
"description": "Picovoice Leopard React Native binding",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
12 changes: 9 additions & 3 deletions binding/react-native/src/leopard.tsx
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 @@ -31,20 +31,26 @@ class Leopard {
* @param modelPath Path to the file containing model parameters.
* @param options Optional configuration arguments.
* @param options.enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion.
* @param options.enableDiarization Set to `true` to enable speaker diarization, which allows Leopard to differentiate speakers
* as part of the transcription process. Word metadata will include a `speakerTag` to identify unique speakers.
* @returns An instance of the engine.
*/
public static async create(
accessKey: string,
modelPath: string,
options: LeopardOptions = {}
) {
const { enableAutomaticPunctuation = false } = options;
const {
enableAutomaticPunctuation = false,
enableDiarization = false
} = options;

try {
let { handle, sampleRate, version } = await RCTLeopard.create(
accessKey,
modelPath,
enableAutomaticPunctuation
enableAutomaticPunctuation,
enableDiarization
);
return new Leopard(handle, sampleRate, version);
} catch (err) {
Expand Down
6 changes: 5 additions & 1 deletion binding/react-native/src/leopard_types.ts
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.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
Expand All @@ -16,6 +16,8 @@ export type LeopardWord = {
endSec: number;
/** Transcription confidence. It is a number within [0, 1]. */
confidence: number;
/** Speaker tag. It is set to `-1` if speaker diarization is not enabled during initialization. */
speakerTag: number;
};

export type LeopardTranscript = {
Expand All @@ -28,4 +30,6 @@ export type LeopardTranscript = {
export type LeopardOptions = {
/** Set to `true` to enable automatic punctuation insertion. */
enableAutomaticPunctuation?: boolean;
/** Set to `true` to enable speaker diarization. */
enableDiarization?: boolean;
};
1 change: 0 additions & 1 deletion binding/react-native/test-app/LeopardTestApp/.ruby-version

This file was deleted.

6 changes: 0 additions & 6 deletions binding/react-native/test-app/LeopardTestApp/Gemfile

This file was deleted.

Loading

0 comments on commit e7d4519

Please sign in to comment.