The Babel Library is a Node.js script that translates EPUB files from one language to another using the OpenAI API. It leverages the power of artificial intelligence to provide automated translation capabilities for EPUB books.
Before running the script, make sure you have the following dependencies installed:
- Node.js (version 14 or higher)
- npm (Node Package Manager)
-
Clone the repository and navigate to the project directory.
-
Install the required dependencies by running the following command:
npm install
This guide will help you set up a .env
file to securely store your OpenAI API key and Org ID. Follow the steps below for a secure configuration.
To locate your Organization ID:
- Navigate to your OpenAI Dashboard.
- Look under the "Organization -> Settings" heading in the left column. Your Organization ID will be listed there.
Before you can create an API key, you must have a valid payment method on file:
- In the dashboard, click on "Organization -> Billing -> Payment methods" in the left column.
- Follow the prompts to add a new payment method.
- On the dashboard, navigate to the "User -> API Keys" section.
- Click on "Create new key".
- Give your key a recognizable name and select the appropriate scope.
- Once the key is generated, click on the "copy" icon next to the key.
- Keep this key safe. For security reasons, OpenAI will only display the full key once.
In the root of your project, create a file named .env
. Add the following lines, replacing ***
with your actual information:
OPEN_AI_ORG=***
OPEN_AI_KEY=***
To translate an EPUB file, update the script.js
file with the desired parameters:
const translationParams = {
...
source: 'English', // Source language of the EPUB file
destination: 'French', // Destination language for translation
};
Specify the source language and destination language for translation as desired.
Run the script by executing the following command:
node script.js path/to/your/file.epub
The script will translate the EPUB file and create a translated version in the destination language.
- JSON parsing errors (API response) are not serious.
- If an error persists, you will either need to lower the value of MAX_TOKENS or
manually add the translation to ./db/Database.json.
- For languages like Chinese, it is possible that certain fields are not translated.
In that case, you will need to remove them from ./db/Database.json and rerun the
script, or translate them manually and modify them in ./db/Database.json.
- Fix: consistency check (word and character ratio), macro translation (paragraph grouping)
- Stable version: starting from August 5, 2023
- Complete documentation: coming soon...
This project is licensed under the MIT License. Feel free to modify and use it according to your needs.
Please note that this script relies on the OpenAI API for translation. Make sure you comply with the OpenAI usage guidelines and any applicable terms and conditions.