This project provides a REST API for converting Thai text into a grapheme-to-phoneme (G2P) representation using Flask. It uses a custom dictionary for word tokenization and romanization to handle words not present in the dictionary.
Before you begin, ensure you have the following installed on your system:
- Python 3.7+: Download Python from python.org.
- Git: For version control and cloning the repository.
- pip: Python's package manager, which comes bundled with Python.
Follow these steps to set up the project:
git clone <REPO_URL>
cd <REPO_NAME>
It's recommended to create a virtual environment to keep the dependencies isolated:
python3 -m venv venv
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On MacOS/Linux:
source venv/bin/activate
Install the required Python packages using pip
:
pip install -r requirements.txt
Start the Flask server:
python thai_g2p_api.py
By default, the server will run on http://localhost:5000.
You can test the API using curl
or Postman. Here’s an example using curl
:
curl -X POST http://localhost:5000/api/g2p -H "Content-Type: application/json" -d '{"text": "สวัสดี"}'
The API will respond with:
{
"result": "sa-wàt-dii"
}
POST /api/g2p
: Converts Thai text into its G2P representation.
Parameter | Type | Description |
---|---|---|
text |
string | Thai text to be converted |
Response:
Field | Type | Description |
---|---|---|
result |
string | representation of the converted Thai text |
This project is licensed under the MIT License. See the LICENSE file for details.