{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"bilingual book maker","text":"

The bilingual_book_maker is an AI translation tool that uses ChatGPT to assist users in creating multi-language versions of epub/txt files and books.

This tool is exclusively designed for translating epub books that have entered the public domain and is not intended for copyrighted works. Before using this tool, please review the project's disclaimer.

"},{"location":"book_source/","title":"Translate from Different Sources","text":""},{"location":"book_source/#txtsrt","title":"txt/srt","text":"

Txt files and srt files are plain text files. This program can translate plain text.

python3 make_book.py --book_name test_books/the_little_prince.txt --test --language zh-hans\n
"},{"location":"book_source/#epub","title":"epub","text":"

epub is made of html files. By default, we only translate contents in <p>. Use --translate-tags to specify tags need for translation. Use comma to separate multiple tags. For example: --translate-tags h1,h2,h3,p,div

bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key} --translate-tags div,p\n

If you want to translate strings in an e-book that aren't labeled with any tags, you can use the --allow_navigable_strings parameter. This will add the strings to the translation queue. Note that it's best to look for e-books that are more standardized if possible.

"},{"location":"book_source/#e-reader","title":"e-reader","text":"

Use --book_from option to specify e-reader type (Now only kobo is available), and use --device_path to specify the mounting point.

# Translate books download from Rakuten Kobo on kobo e-reader\nbbook_maker --book_from kobo --device_path /tmp/kobo\n
"},{"location":"cmd/","title":"Command Line Options","text":""},{"location":"cmd/#test-translate","title":"Test translate","text":"

--test

Use this option to preview the result if you haven't paid for the service or just want to test. Note that there is a limit and it may take some time.

bbook_maker --book_name test_books/Lex_Fridman_episode_322.srt --openai_key ${openai_key}  --test\n
bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key}  --test --language zh-hans\n

--test_num <TEST_NUM>

Use this option to set how many paragraph you want to translate for testing. Default is 10.

"},{"location":"cmd/#resume","title":"Resume","text":"

--resume

Use this option to manually resume the process after an interruption.

"},{"location":"cmd/#retranslate-epub-only","title":"Retranslate (epub only)","text":"

--retranslate <translated_filepath, file_name_in_epub, start_str [, end_str]>

If a file in epub is not translated well, it supports to re-translate part of epub separately.

This option take 4 arguments: translated_filepath, file_name_in_epub, start_str, end_str. end_str is optional.

Warning:

It deletes from the tag at start_str of the finished book to the next tag at end_str, and then re-translates.

Therefore, please make sure that the next tag of end_str is the translated content. (If end_str is not provided, the next label of start_str is guaranteed to be the translated content.) There can be missing translations between the two strings, but if end_str is not translated, there will be problems.

"},{"location":"cmd/#customize-output-style-epub-only","title":"Customize output style (epub only)","text":"

--translation_style <TRANSLATION_STYLE>

Support changing the output style of epub files.

bbook_maker --book_name test_books/animal_farm.epub --translation_style \"color: #4a4a4a; font-style: normal; background-color: #f7f7f7; padding: 5px; margin: 10px 0; border-radius: 5px;\"\n

"},{"location":"cmd/#proxy","title":"Proxy","text":"

--proxy <PROXY>

Use this option to specify proxy server for internet access. Enter a string such as http://127.0.0.1:7890 .

"},{"location":"cmd/#api-base","title":"API base","text":"

--api_base <API_BASE_URL>

If you want to change api_base like using Cloudflare Workers, use this option to support it.

bbook_maker --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'\n

Note: the api url should be 'https://xxxx/v1'. Quotation marks are required.

"},{"location":"cmd/#microsoft-azure-endpoints","title":"Microsoft Azure Endpoints","text":"

--api_base <API_BASE_URL> --deployment_id <DEPLOYMENT_ID>

You can use the api endpoint provided from Microsoft.

bbook_maker --book_name 'animal_farm.epub' --openai_key XXXXX --api_base 'https://example-endpoint.openai.azure.com' --deployment_id 'deployment-name'\n

Note : Current only support chatgptapi model for deployment_id. And api_base must be provided when using deployment_id. You can check here for more information about deployment_id.

"},{"location":"cmd/#batch-size-txt-only","title":"Batch size (txt only)","text":"

--batch_size

Use this parameter to specify the number of lines for batch translation. Default is 10. (Currently only effective for txt files).

python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch_size 20\n
"},{"location":"cmd/#accumulated-num","title":"Accumulated Num","text":"

--accumulated_num <ACCUMULATED_NUM>

Wait for how many tokens have been accumulated before starting the translation. gpt3.5 limits the total_token to 4090.

For example, if you use --accumulated_num 1600, maybe openai will output 2200 tokens and maybe 200 tokens for other messages in the system messages user messages. 1600+2200+200=4000, so you are close to the limit.

You have to choose your own value, there is no way to tell if the limit is reached before sending request.

"},{"location":"disclaimer/","title":"Disclaimer","text":"
  1. The purpose of this project, bilingual_book_maker, is to assist users in creating multilingual versions of epub files and books. It is only applicable to books that have entered the public domain and is not intended for use with copyrighted material. We strongly advise users to read the copyright information carefully before using this project and to comply with relevant laws and regulations in order to protect their own and others' rights.
  2. In no event shall the authors or developers be liable for any loss or damage caused by the use of this project. Users assume all risks associated with the use of this project. Users must confirm that they have obtained permission from the original copyright holder or used open source EPUB files before using this project to avoid potential copyright risks.

If you have any concerns or suggestions about the use of this project, please contact us through the issues section.

\u514d\u8d23\u58f0\u660e\uff1a

  1. \u8be5\u9879\u76ee\u8bbe\u8ba1\u76ee\u7684\u662f\u4e3a\u4e86\u5e2e\u52a9\u7528\u6237\u5236\u4f5c\u591a\u8bed\u8a00\u7248\u672c\u7684epub\u6587\u4ef6\u548c\u56fe\u4e66\uff0c\u4ec5\u9002\u7528\u4e8e\u8fdb\u5165\u516c\u5171\u7248\u6743\u9886\u57df\u4e66\u7c4d\uff0c\u4e0d\u9002\u7528\u4e8e\u6709\u7248\u6743\u7684\u4e66\u7c4d\u3002\u6211\u4eec\u5f3a\u70c8\u5efa\u8bae\u7528\u6237\u5728\u4f7f\u7528\u8be5\u9879\u76ee\u65f6\u4ed4\u7ec6\u9605\u8bfb\u5176\u7248\u6743\u4fe1\u606f\u5e76\u9075\u5b88\u76f8\u5173\u6cd5\u5f8b\u548c\u89c4\u5b9a\uff0c\u4ee5\u4fdd\u62a4\u81ea\u5df1\u548c\u4ed6\u4eba\u7684\u6743\u76ca\u3002
  2. \u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\uff0c\u4f5c\u8005\u548c\u5f00\u53d1\u8005\u4e0d\u5bf9\u56e0\u4f7f\u7528\u8be5\u9879\u76ee\u800c\u5bfc\u81f4\u7684\u4efb\u4f55\u635f\u5931\u6216\u635f\u5bb3\u627f\u62c5\u4efb\u4f55\u8d23\u4efb\u3002\u4f7f\u7528\u8be5\u9879\u76ee\u7684\u98ce\u9669\u7531\u7528\u6237\u81ea\u884c\u627f\u62c5\u3002\u7528\u6237\u5fc5\u987b\u5728\u4f7f\u7528\u8be5\u9879\u76ee\u4e4b\u524d\uff0c\u786e\u8ba4\u5176\u5df2\u83b7\u5f97\u4e86\u539f\u8457\u4f5c\u6743\u4eba\u7684\u8bb8\u53ef\u6216\u4f7f\u7528\u4e86\u516c\u5f00\u53ef\u7528\u7684\u5f00\u6e90EPUB\u6587\u4ef6\uff0c\u4ee5\u907f\u514d\u53ef\u80fd\u5b58\u5728\u7684\u7248\u6743\u98ce\u9669\u3002

\u5982\u679c\u60a8\u5bf9\u8be5\u9879\u76ee\u7684\u4f7f\u7528\u6709\u4efb\u4f55\u7591\u8651\u6216\u5efa\u8bae\uff0c\u8bf7\u901a\u8fc7 issues \u4e0e\u6211\u4eec\u8054\u7cfb\u3002

"},{"location":"env_settings/","title":"Environment Settings","text":"

You can also write information into env to skip some options.

"},{"location":"env_settings/#model-keys","title":"Model keys","text":"
# Set env BBM_OPENAI_API_KEY to ignore option --openai_key\nexport BBM_OPENAI_API_KEY=${your_api_key}\n\n# Set env BBM_CAIYUN_API_KEY to ignore option --caiyun_key\nexport BBM_CAIYUN_API_KEY=${your_api_key}\n
"},{"location":"installation/","title":"Installation","text":""},{"location":"installation/#pip","title":"pip","text":"

bilingual_book_maker has been published as a Python package and can be install by pip. (Recommend in a virtual environment.)

pip install -U bbook_maker\n
"},{"location":"installation/#git","title":"git","text":"

You can also install from github if you want to use the latest version.

git clone git@github.com:yihong0618/bilingual_book_maker.git\npip install .\n
"},{"location":"model_lang/","title":"Model and Languages","text":""},{"location":"model_lang/#models","title":"Models","text":"

-m, --model <Model>

Currently bbook_maker supports these models: chatgptapi , gpt3 , google , caiyun , deepl , deeplfree , gpt4 , gpt4omini , o1-preview , o1 , o1-mini , o3-mini , claude , customapi. Default model is chatgptapi .

"},{"location":"model_lang/#openai-models","title":"OPENAI models","text":"

There are three models you can choose from.

Note 1: Use --openai_key option to specify OpenAI API key. If you have multiple keys, separate them by commas (xxx, xxx, xxx) to reduce errors caused by API call limits.

Note 2: You can just set the environment variable BBM_OPENAI_API_KEY instead the openai_key. See Environment setting.

"},{"location":"model_lang/#caiyun","title":"CAIYUN","text":"

Using Caiyun model to translate. The api currently only support:

  1. Simplified Chinese <-> English
  2. Simplified Chinese <-> Japanese

The official Caiyun has provided a test token (3975l6lr5pcbvidl6jl2). You can apply your own token by following this [tutorial].(https://bobtranslate.com/service/translate/caiyun.html)

bbook_maker --model caiyun --caiyun_key 3975l6lr5pcbvidl6jl2 --book_name test_books/animal_farm.epub\n
"},{"location":"model_lang/#deepl","title":"DEEPL","text":"

There are two models you can choose from.

"},{"location":"model_lang/#claude","title":"Claude","text":"

Support Claude model. Use --model claude --claude_key ${claude_key} .

bbook_maker --book_name test_books/animal_farm.epub --model claude --claude_key ${claude_key}\n
"},{"location":"model_lang/#custom-api","title":"Custom API","text":"

Support CustomAPI model. Use --model customapi --custom_api ${custom_api} .

bbook_maker --book_name test_books/animal_farm.epub --model customapi --custom_api ${custom_api}\n
"},{"location":"model_lang/#google","title":"Google","text":"

Support google model. Use --model google

"},{"location":"model_lang/#languages","title":"Languages","text":"

--language <LANGUAGE>

Set target languages. All models except for caiyun supports lots of languages. You can use bbook_maker --help to check available languages. Default target language is \"Simplified Chinese\" .

bbook_maker --book_name test_books/animal_farm.epub --model chatgptapi --openai_key ${openai_key} --language ja\n
bbook_maker --book_name test_books/animal_farm.epub --model chatgptapi --openai_key ${openai_key} --language \"Simplified Chinese\"\n
"},{"location":"prompt/","title":"Tweak the prompt","text":"

To tweak the prompt, use the --prompt parameter. Valid placeholders for the user role template include {text} and {language}. It supports a few ways to configure the prompt:

You can also set the user and system role prompt by setting environment variables: BBM_CHATGPTAPI_USER_MSG_TEMPLATE and BBM_CHATGPTAPI_SYS_MSG.

"},{"location":"prompt/#examples","title":"Examples","text":"
python3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_template_sample.txt\n# or\npython3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_template_sample.json\n# or\npython3 make_book.py --book_name test_books/animal_farm.epub --prompt \"Please translate \\`{text}\\` to {language}\"\n
"},{"location":"quickstart/","title":"QuickStart","text":"

After successfully install the package, you can see bbook-maker is in the output of pip list.

"},{"location":"quickstart/#preparation","title":"Preparation","text":"
  1. ChatGPT or OpenAI token
  2. epub/txt books
  3. Environment with internet access or proxy
  4. Python 3.8+
"},{"location":"quickstart/#use","title":"Use","text":"

You can use by command bbook_maker. A sample book, test_books/animal_farm.epub, is provided for testing purposes.

bbook_maker --book_name ${path of a book} --openai_key ${openai_key}\n\n# Example\nbbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key}\n

Or, you can use the script provided by repository.

python3 make_book.py --book_name ${path of a book} --openai_key ${openai_key}\n\n# Example\npython3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key}\n

Once the translation is complete, a bilingual book named ${book_name}_bilingual.epub would be generated.

Note: If there are any errors or you wish to interrupt the translation by pressing CTRL+C. A book named ${book_name}_bilingual_temp.epub would be generated. You can simply rename it to any desired name.

"}]}