CocoaPods trunk is moving to be read-only. Read more on the blog, there are 10 months to go.

Zebra-iOS 1.0.0

Zebra-iOS 1.0.0

Maintained by Kwangsoo Yeo.



Zebra-iOS 1.0.0

  • By
  • Picovoice

Zebra

GitHub release GitHub

Maven Central npm CocoaPods PyPI

Made in Vancouver, Canada by Picovoice

Twitter URL YouTube Channel Views

Zebra is a lightweight, on-device neural machine translation engine.

Table of Contents

Demos

Python Demos

Install the demo package:

pip3 install pvzebrademo

Run the following in the terminal:

zebra_demo --access_key ${ACCESS_KEY} --model_path ${MODEL_PATH} --text ${TEXT}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_PATH} with a supported translation model located here and ${TEXT} with the text to translate.

For more information about Python demos go to demo/python.

C Demos

Build the demo:

cmake -S demo/c/ -B demo/c/build && cmake --build demo/c/build

Run the demo:

./demo/c/build/zebra_demo -a ${ACCESS_KEY} -l ${LIBRARY_PATH} -m ${MODEL_PATH} -t ${TEXT}

Replace ${LIBRARY_PATH} with path to appropriate library available under lib, ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_PATH} with a supported translation model located here and ${TEXT} with the text to translate.

For more information about C demos go to demo/c.

Android Demos

Using Android Studio, open demo/android/ZebraDemo as an Android project.

Replace "${YOUR_ACCESS_KEY_HERE}" in the file MainActivity.java with your AccessKey.

Go to Build > Select Build Variant... and select the language you would like to run the demo in (e.g. enfrDebug -> English to French translation demo)

Build and run on an installed simulator or a connected Android device.

For more information about Android demos go to demo/android.

iOS Demos

  1. Open ZebraDemo.xcodeproj in XCode.
  2. Replace ${YOUR_ACCESS_KEY_HERE} in the file ViewModel.swift with your AccessKey.
  3. Go to Product > Scheme and select the scheme for the language you would like to run the demo in (e.g. enfrDemo -> English to French translation demo).
  4. Run the demo with a simulator or connected iOS device.
  5. Once the demo app has started, enter the text you wish to translate in the text box area, and press the Translate button to translate the text.

For more information about iOS demos go to demo/ios.

Web Demos

From demo/web run the following in the terminal:

yarn
yarn start [${SOURCE}] [${TARGET}]

(or)

npm install
npm run start [${SOURCE}] [${TARGET}]

Replace ${SOURCE} and ${TARGET} with the source/target language you would like to run the demo in.

Open http://localhost:5000 in your browser to try the demo.

For more information about Web demos go to demo/web.

SDKs

Python

Install the Python SDK:

pip3 install pvzebra

Create an instance of the engine and perform text translation:

import pvzebra

zebra = pvzebra.create(access_key='${ACCESS_KEY}', model_path='${MODEL_PATH}')

print(zebra.translate('${TEXT}'))

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_PATH} with a supported translation model located here and ${TEXT} with the text to translate.

Finally, when done be sure to explicitly release the resources:

zebra.delete()

C

Android

To include the Zebra package in your Android project, ensure you have included mavenCentral() in your top-level build.gradle file and then add the following to your app's build.gradle:

dependencies {
    implementation 'ai.picovoice:zebra-android:${LATEST_VERSION}'
}

Create an instance of the engine and translate text:

import ai.picovoice.zebra.*;

final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
final String modelPath = "${MODEL_FILE_PATH}";
try {
    Zebra zebra = new Zebra.Builder()
        .setAccessKey(accessKey)
        .setModelPath(modelPath)
        .build(appContext);
    String translation = zebra.translate("${TEXT}");
} catch (ZebraException e) { }

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_FILE_PATH} with a Zebra model file and ${TEXT} with the text to be translated.

iOS

Create an instance of the engine:

import Zebra

let modelPath = Bundle(for: type(of: self)).path(
        forResource: "${MODEL_FILE}", // Name of the model file name for Zebra
        ofType: "pv")!

do {
  let zebra = try Zebra(accessKey: "${ACCESS_KEY}", modelPath: modelPath)
} catch {}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${MODEL_FILE} with the model file name for Zebra.

Translate

do {
    let translation = try zebra.translate(text: "${TEXT}")
} catch {}

Replace ${TEXT} with the text to be translated.

Release resources

When done be sure to explicitly release the resources using zebra.delete().

For more details, see the iOS SDK.

Web

Install the web SDK using yarn:

yarn add @picovoice/zebra-web

or using npm:

npm install --save @picovoice/zebra-web

Create an instance of the engine using ZebraWorker and translate text:

import { ZebraWorker } from "@picovoice/zebra-web";
import zebraParams from "${PATH_TO_BASE64_ZEBRA_PARAMS}";

const zebra = await ZebraWorker.create(
  "${ACCESS_KEY}",
  { base64: zebraParams },
);

const translation = await zebra.translate("${TEXT}");
console.log(translation);

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console. Finally, when done release the resources using zebra.release().

For more details, see the Web SDK.

Releases