PHPackages                             1338/nativephp-tflite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 1338/nativephp-tflite

ActiveNativephp-plugin[Utility &amp; Helpers](/categories/utility)

1338/nativephp-tflite
=====================

NativePHP plugin for TensorFlow Lite model storage, metadata, and inference

v0.1.0(1mo ago)04MITKotlinPHP ^8.3

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/1338/nativephp-tflite-plugin)[ Packagist](https://packagist.org/packages/1338/nativephp-tflite)[ RSS](/packages/1338-nativephp-tflite/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

NativePHP TFLite
================

[](#nativephp-tflite)

[![Packagist Version](https://camo.githubusercontent.com/3a2c497a42f9f46d792c345b0c108cac19d165b693ad1632d6461e3373233de7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f313333382f6e61746976657068702d74666c6974652e737667)](https://packagist.org/packages/1338/nativephp-tflite)

NativePHP plugin for loading TensorFlow Lite models and running on-device inference from PHP or JavaScript.

This project is intentionally scoped as a small TFLite bridge, not a wakeword engine. Android and iOS do not provide reliable custom wakeword support in the way this project originally explored, so the useful surface is model storage, model metadata, and direct inference.

Status
------

[](#status)

- Android: implemented for single-input models.
- iOS: bridge stubs only; not implemented yet.
- Supported tensor types: `FLOAT32`, `INT32`, `UINT8`, and `INT8`.
- Current limitation: one input tensor per model. Multiple outputs are supported by choosing an `outputIndex`.
- Build validation: installed from Packagist into a clean NativePHP Mobile 3.3 app and compiled with `./gradlew assembleRelease`.

Requirements
------------

[](#requirements)

- NativePHP Mobile 3 app.
- PHP 8.3+.
- Android min SDK 33 or higher.
- Android project generated by NativePHP.
- TensorFlow Lite Android dependency from `nativephp.json`.

Install
-------

[](#install)

Require and register the plugin from your NativePHP mobile app:

```
composer require 1338/nativephp-tflite
php artisan native:plugin:register 1338/nativephp-tflite
php artisan native:plugin:validate
php artisan native:install --force
```

PHP Usage
---------

[](#php-usage)

Load a model bundled in Android assets:

```
use OneThreeThreeEight\NativephpTflite\Tflite;

$info = Tflite::loadModelFromAsset('models/example.tflite');
```

Store a model in app storage:

```
$base64 = base64_encode(file_get_contents('/local/path/to/model.tflite'));

Tflite::addModel('model.tflite', $base64);
Tflite::loadModelFromFile('model.tflite');
```

Inspect the loaded model:

```
$info = Tflite::modelInfo();
```

Run inference:

```
$result = Tflite::run([
    0.1,
    0.2,
    0.3,
]);

$output = $result['data'];
```

The input array is flattened before being passed to TensorFlow Lite, so nested arrays are allowed:

```
$result = Tflite::run([
    [0.1, 0.2],
    [0.3, 0.4],
]);
```

For models with multiple outputs, choose the output tensor:

```
$result = Tflite::run($input, outputIndex: 1);
```

JavaScript Usage
----------------

[](#javascript-usage)

```
import {
  loadModelFromAsset,
  loadModelFromFile,
  modelInfo,
  run,
} from '/_native/plugins/tflite/tflite.js';

await loadModelFromAsset('models/example.tflite');

const info = await modelInfo();
const result = await run([0.1, 0.2, 0.3]);
```

API
---

[](#api)

### `Tflite::loadModelFromAsset(string $asset): ?array`

[](#tfliteloadmodelfromassetstring-asset-array)

Loads a `.tflite` model from Android assets and returns model metadata.

### `Tflite::addModel(string $name, string $base64Data): ?array`

[](#tfliteaddmodelstring-name-string-base64data-array)

Stores a base64-encoded model in app-private storage under `tflite_models/`.

### `Tflite::listModels(): array`

[](#tflitelistmodels-array)

Returns stored model files with `name`, `size`, and `lastModified`.

### `Tflite::deleteModel(string $name): bool`

[](#tflitedeletemodelstring-name-bool)

Deletes a stored model file.

### `Tflite::loadModelFromFile(string $filename): ?array`

[](#tfliteloadmodelfromfilestring-filename-array)

Loads a model previously stored with `addModel()` or `copyAssetToStorage()`.

### `Tflite::copyAssetToStorage(string $assetName, string $targetName): ?array`

[](#tflitecopyassettostoragestring-assetname-string-targetname-array)

Copies a bundled asset model into app-private model storage.

### `Tflite::modelInfo(): ?array`

[](#tflitemodelinfo-array)

Returns metadata for the currently loaded model:

```
[
    'loaded' => true,
    'model' => 'file:model.tflite',
    'inputs' => [
        [
            'index' => 0,
            'name' => 'serving_default_input',
            'shape' => [1, 224, 224, 3],
            'dataType' => 'FLOAT32',
            'bytes' => 602112,
        ],
    ],
    'outputs' => [
        [
            'index' => 0,
            'name' => 'StatefulPartitionedCall',
            'shape' => [1, 1001],
            'dataType' => 'FLOAT32',
            'bytes' => 4004,
        ],
    ],
]
```

### `Tflite::run(array $input, int $outputIndex = 0): ?array`

[](#tfliterunarray-input-int-outputindex--0-array)

Runs inference against the loaded model.

Return shape:

```
[
    'outputIndex' => 0,
    'shape' => [1, 1001],
    'dataType' => 'FLOAT32',
    'data' => [0.01, 0.93, 0.06],
]
```

Security Notes
--------------

[](#security-notes)

- Stored model names are sanitized to a basename before writing to app storage.
- Models are stored in the app-private files directory.
- This plugin does not download models by itself. If your app downloads models, validate source, integrity, size, and expected tensor metadata before loading.

Roadmap
-------

[](#roadmap)

- Add tests for PHP facade behavior.
- Add Kotlin tests for tensor flattening and output decoding.
- Support multiple input tensors.
- Add optional output reshaping instead of returning a flat array only.
- Implement iOS with TensorFlow Lite Swift or document Android-only support permanently.

Not Goals
---------

[](#not-goals)

- Wakeword detection.
- Background audio capture.
- Always-on microphone behavior.
- Model training or conversion.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bda33d6cd3572015f89da20e18c7d20ce71a8c981c3a0ea38bc070953dca5e4?d=identicon)[1338](/maintainers/1338)

---

Top Contributors

[![1338](https://avatars.githubusercontent.com/u/3015701?v=4)](https://github.com/1338 "1338 (5 commits)")

---

Tags

inferenceandroidnativephptensorflow-litetflite

### Embed Badge

![Health badge](/badges/1338-nativephp-tflite/health.svg)

```
[![Health](https://phpackages.com/badges/1338-nativephp-tflite/health.svg)](https://phpackages.com/packages/1338-nativephp-tflite)
```

###  Alternatives

[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k34.7M92](/packages/jetbrains-phpstorm-stubs)[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.6M30](/packages/rubix-ml)[nativephp/mobile

NativePHP for Mobile

1.1k102.1k154](/packages/nativephp-mobile)[nativephp/php-bin

PHP binaries used by the NativePHP framework

138262.1k5](/packages/nativephp-php-bin)[symfony/ai-platform

PHP library for interacting with AI platform provider.

521.6M378](/packages/symfony-ai-platform)[dmamontov/favicon

Class generation favicon for browsers and devices Android, Apple, Windows and display of html code. It supports a large number of settings such as margins, color, compression, three different methods of crop and screen orientation.

533.7k](/packages/dmamontov-favicon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
