Skip to content

amadeomano/persian-tts

Repository files navigation

Persian Text-to-Speach synthesizer

PersianTTS is GPLv3 licensed.

Persian TTS is a simple text-to-speach synthesizing engine and ReactNative app that I have initially developed as my Bachelor's degree graduation project.

The project is however meant to get gradual improvements over time.

Contents

βœ… Requirements

Persian-TTS apps are powered by React Native so you will need it for compiling the apps properly. To compile android version, having a proper Android SDK on your machine is a must and evidently compiling iOS varient needs you to have a working Xcode copy and a functional Cocoapods dependency management tool on a MacOS operating system powered machine.

You will also need to have a dependency management tool for accessing NPM and download project's dependencies. Yarn is used in this project but NPM or other tools could also be used.

πŸ—Ί Installation guide

First you can get the source code by cloning it

git clone git@github.com:amfolio/persian-tts.git

iOS dependencies installation (Optional)

cd ios
pod install

Then move to the package's directory and install it's dependencies using yarn install or npm install

πŸš€ Launching apps

To launch apps in emulators of Android and/or iOS operating systems, you can use following commands:

Android

react-native run-android

iOS

react-native run-ios

πŸ— Project structure

This project's structure is just identical to many other ReactNative project structures. below is just a big picture of the main structure:

  • __tests__ : Jest powered unit tests
  • android : ReactNative android source files
  • ios : ReactNative ios source files
  • src : Main project root
    • components : Reusable React components
      • ComponentName : A CamelCase named folder wrapping over component files
        • index.js : The component entry point, exporting it's contents using ES6 modules
        • styles.js (optional): component's ReactNative style-sheets
    • screen : Application screen components
    • utils : Synthesizer algorithms & other language processing tools
    • App.js : Main application entry
    • Router.js : React-Navigation component configurations
    • voices.json : Application wide available voices configs

πŸ›  How it works

Shortly the project uses a "concatnative synthesizing" apprach to achieve it's goal. In persian language, an unlimited set of words could be constructed by concatnating "consonant+vowel" pairs. For bravity here we call these pairs simply "Syllables".

To make the synthesizing work, the project has initially a set of 169 syllable voices, recoded from my own voice (so it's not a professional narration πŸ˜…). this number is devided as bellow:

Voice type Corresponding files count
vowels 6
silent consonants 23
syllable (consonant+vowel) 138
spaces 2
Total 169

The synthesizing process is then feasable by concatnating syllables using FFmpeg library and it's react-native-ffmpeg wrapper. Here is a quick schema of what happens.

1️⃣ Step 1

In the first step, the phonetic corresponding for of persian input is created using TextToPhonems utility function.

const input = "Ψ³Ω„Ψ§Ω…"; // means "Hello" in persian
const output = textToPhonems(input); // ["sa", "lā", "m"];

2️⃣ Step 2

The result of step 1 passes through PhonemsToFFMpeg utility function and gets a valid ffmpeg concatnation command:

const ffmpeg = phonemsToFFMpeg(output);

and the result would be:

ffmpeg \
  -I sa.wav -I lā.wav -I m.wav \
  -filter_complex β€˜[0:0][1:0][2:0]concat=n=3:v=0:a=1[out]’ \
  -map β€˜[out]’ output.wav

3️⃣ Step 3

The application calls ffmpeg using react-native-ffmpeg and the following steps get done behind the scenes:

Before concatnation
sa.wav lā.wav m.wav
After concatnation
output.wav

4️⃣ Step 4

The output audio file gets played over both iOS and Android platforms thanks to react-native-sound library. Reading bundle resources and transfering them to sandbox/SD-card location is also possible thanks to react-native-fs

πŸ™πŸ» Acknowledgments

The special thank you goes to my project's director, Dr. Mohammad Taheri who gave me the confidence of approaching this subject and guided me through the best steps to make it possible. Without him I would have probably never get into such academic researches.

The next big thanks goes to the developers community who generousely share the cutting edge technology with others. It's just thanks to this community that reinventing the wheels is not anymore necessary.

Here is a short list of libraries who helped me infinitely in my development path:

🀝 Contribution

This repository is initially constructed as a minimum effort for a Persian language open-source Text-To-Speech solution. I would be highly grateful of any contribution from issues reporting to bugfixes and improvements.

Contribution by adding more voices to the project is also highly welcomed and you can also mention your name in voices.json.

Please feel free to send pull requests in case of feeling any necessity.