PHPackages                             eru/avro-phonetic - 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. eru/avro-phonetic

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eru/avro-phonetic
=================

Avro Phonetic - Bengali/Bangla transliteration library for PHP and Laravel

v1.0.0(4mo ago)511GPL-3.0-or-laterPHPPHP &gt;=5.6

Since Dec 28Pushed 4mo agoCompare

[ Source](https://github.com/imerfanahmed/avro-php)[ Packagist](https://packagist.org/packages/eru/avro-phonetic)[ RSS](/packages/eru-avro-phonetic/feed)WikiDiscussions main Synced 1mo ago

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

Avro Phonetic
=============

[](#avro-phonetic)

[![Latest Version on Packagist](https://camo.githubusercontent.com/37d2803b0f9a9f2e36c40a42e158fbd9d5ee16366c1700b8675b3e7ff211040a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6572752f6176726f2d70686f6e657469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eru/avro-phonetic)[![Total Downloads](https://camo.githubusercontent.com/d1dcc0bc37bdad5fa8c941a0c487f096e9c3f9fdf745bd3ef09e909792e7764d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6572752f6176726f2d70686f6e657469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eru/avro-phonetic)[![License](https://camo.githubusercontent.com/066eaff9bf97af9d93b53680fd0929a17a0a44cd1399439c6c9e6185e4770b09/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6572752f6176726f2d70686f6e657469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eru/avro-phonetic)[![PHP Version](https://camo.githubusercontent.com/8ea640ae241a28d3a1c87ed22ae17ee5c32a2c9b16667791e1b42a721088abaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6572752f6176726f2d70686f6e657469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eru/avro-phonetic)

A high-performance **Avro Phonetic** transliteration library for PHP. Convert Banglish (Romanized Bengali) to Bengali script with blazing-fast Trie-based pattern matching and context-sensitive rule engine.

```
ami banglay gan gai → আমি বাংলায় গান গাই

```

✨ Features
----------

[](#-features)

- 🚀 **Trie-Based Pattern Matching** — O(m) lookup time instead of O(n×m) linear search
- 🎯 **Context-Sensitive Rules** — Intelligent conversion based on surrounding characters
- 🔌 **Laravel Ready** — Auto-discovery, Facade, and config publishing out of the box
- 📦 **Standalone Compatible** — Works with any PHP project, no framework required
- 🧪 **Fully Tested** — 180+ tests covering all functionality
- ⚡ **Memory Efficient** — Singleton pattern with lazy-loaded grammar
- 🔧 **PHP 5.6+** — Compatible with PHP 5.6 through 8.x

🎯 What Makes This Unique?
-------------------------

[](#-what-makes-this-unique)

### Trie Data Structure for Fast Lookups

[](#trie-data-structure-for-fast-lookups)

Unlike traditional implementations that linearly scan through hundreds of patterns, we use a **Trie (prefix tree)** data structure. This provides:

- **O(m) lookup time** where m is the pattern length (vs O(n×m) for linear search)
- **Efficient longest-match finding** — automatically finds the longest matching pattern
- **Minimal memory overhead** — shared prefixes are stored only once

### Context-Sensitive Rule Engine

[](#context-sensitive-rule-engine)

Our rule engine understands context! The same input can produce different outputs based on what comes before or after:

```
Avro::to('rri');   // ঋ (at word start)
Avro::to('krri');  // কৃ (after consonant)

Avro::to('OI');    // ঐ (standalone)
Avro::to('kOI');   // কৈ (after consonant)
```

**Supported rule scopes:**

- `vowel` / `!vowel` — Check if prefix/suffix is a vowel
- `consonant` / `!consonant` — Check if prefix/suffix is a consonant
- `punctuation` / `!punctuation` — Check for word boundaries
- `exact` / `!exact` — Match specific characters

📦 Installation
--------------

[](#-installation)

```
composer require eru/avro-phonetic
```

🚀 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use Eru\AvroPhonetic\Avro;

// Static method
echo Avro::to('ami banglay gan gai');
// Output: আমি বাংলায় গান গাই

// Instance method
$avro = new Avro();
echo $avro->parse('amar sonar bangla');
// Output: আমার সনার বাংলা
```

### Helper Functions

[](#helper-functions)

```
// Quick conversion
echo avro('bangladesh');  // বাংলাদেশ
echo bangla('dhaka');     // ঢাকা

// Get instance for chaining
$result = avro()->parse('tumi kemon acho');
```

### Laravel Usage

[](#laravel-usage)

The package auto-registers with Laravel 5.5+. No additional setup required!

**Using the Facade:**

```
use Eru\AvroPhonetic\Facades\Avro;

// In your controller
public function store(Request $request)
{
    $bengaliText = Avro::to($request->input('text'));
    // ...
}
```

**In Blade templates:**

```
{{ avro('ami tomake bhalobashi') }}
{{ bangla('sundor bangladesh') }}
```

**Publish configuration (optional):**

```
php artisan vendor:publish --tag=avro-phonetic-config
```

This creates `config/avro-phonetic.php` where you can customize the grammar file path.

📖 API Reference
---------------

[](#-api-reference)

### Avro Class

[](#avro-class)

```
use Eru\AvroPhonetic\Avro;

// Static conversion
Avro::to(string $text): string

// Instance methods
$avro = new Avro();
$avro->parse(string $text): string
$avro->convert(string $text): string  // Alias for parse()

// Factory methods
Avro::getInstance(): Avro                        // Singleton
Avro::withGrammar(array $grammar): Avro          // Custom grammar
Avro::fromGrammarFile(string $path): Avro        // Load from file

// Access parser
$avro->getParser(): PhoneticParser
```

### Helper Functions

[](#helper-functions-1)

```
// Convert text or get instance
avro(?string $text = null): Avro|string

// Always converts text
bangla(string $text): string
```

⚙️ Advanced Usage
-----------------

[](#️-advanced-usage)

### Custom Grammar

[](#custom-grammar)

You can provide your own grammar rules:

```
$customGrammar = [
    'patterns' => [
        ['find' => 'ph', 'replace' => 'ফ', 'rules' => []],
        // ... more patterns
    ],
    'vowel' => 'aeiou',
    'consonant' => 'bcdfghjklmnpqrstvwxyz',
    'number' => '1234567890',
    'casesensitive' => 'oiudgjnrstyz',
];

$avro = Avro::withGrammar($customGrammar);
echo $avro->parse('phone'); // ফনে
```

### Load Grammar from File

[](#load-grammar-from-file)

```
$avro = Avro::fromGrammarFile('/path/to/custom-grammar.json');
```

### Direct Parser Access

[](#direct-parser-access)

For performance-critical applications, access the parser directly:

```
use Eru\AvroPhonetic\PhoneticParser;

$grammar = json_decode(file_get_contents('grammar.json'), true);
$parser = new PhoneticParser($grammar);

// Parse multiple texts
foreach ($texts as $text) {
    $results[] = $parser->parse($text);
}
```

🏎️ Performance
--------------

[](#️-performance)

Benchmarks on typical hardware (PHP 8.x):

OperationTimeSingle word conversion~0.05msSentence (10 words)~0.1msParagraph (100 words)~0.8msTrie initialization~15ms (one-time)The Trie is built once and reused via singleton pattern, making subsequent conversions extremely fast.

🧪 Testing
---------

[](#-testing)

```
# Run all tests
composer test

# Or directly with PHPUnit
./vendor/bin/phpunit

# Run specific test suite
./vendor/bin/phpunit --testsuite Parser
./vendor/bin/phpunit --testsuite Performance

# With coverage report
./vendor/bin/phpunit --coverage-html coverage
```

📁 Project Structure
-------------------

[](#-project-structure)

```
avro-phonetic/
├── src/
│   ├── Avro.php                    # Main entry point
│   ├── PhoneticParser.php          # Core parser with rule engine
│   ├── Trie.php                    # Trie data structure
│   ├── TrieNode.php                # Trie node class
│   ├── AvroPhoneticServiceProvider.php  # Laravel service provider
│   ├── Facades/
│   │   └── Avro.php                # Laravel facade
│   └── helpers.php                 # Global helper functions
├── config/
│   └── avro-phonetic.php           # Laravel config
├── resources/
│   └── grammar.json                # Avro phonetic rules
└── tests/
    ├── AvroTest.php
    ├── PhoneticParserTest.php
    ├── RuleEngineTest.php
    ├── TrieTest.php
    └── ...

```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Write tests for your changes
4. Ensure all tests pass (`composer test`)
5. Commit your changes (`git commit -m 'Add amazing feature'`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the [GPL-3.0 License](LICENSE).

🙏 Credits
---------

[](#-credits)

- Based on the [Avro Phonetic](https://avro.im) keyboard layout
- Rule engine ported from [pyAvroPhonetic](https://github.com/kaustavdm/pyAvroPhonetic) by Kaustav Das Modak
- Developed by [Erfan Ahmed Siam](https://github.com/imerfanahmed)

---

 Made with ❤️ for the Bengali language

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance81

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

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

132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e45c40db384ce48b54e8a4a1ee2fd115cece0491d2276d8d93367148c796a6e7?d=identicon)[erfan](/maintainers/erfan)

---

Top Contributors

[![imerfanahmed](https://avatars.githubusercontent.com/u/28698119?v=4)](https://github.com/imerfanahmed "imerfanahmed (6 commits)")

---

Tags

avroavro-phpbanglabengalilaravelphoneticphptransliterationlaraveltransliterationavroBanglaphoneticbengali

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eru-avro-phonetic/health.svg)

```
[![Health](https://phpackages.com/badges/eru-avro-phonetic/health.svg)](https://phpackages.com/packages/eru-avro-phonetic)
```

###  Alternatives

[mirazmac/bangla-string

A wannabe all-in-all Bangla String Manupulation Library!

103.0k](/packages/mirazmac-bangla-string)[stephenjude/filament-blog

Filament Blog Builder

20317.8k](/packages/stephenjude-filament-blog)[rakibhstu/number-to-bangla

A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.

8310.2k](/packages/rakibhstu-number-to-bangla)[datomatic/nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.

11229.2k](/packages/datomatic-nova-detached-actions)

PHPackages © 2026

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