Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-epub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:
run: |
mkdir -p epub/brf
pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt
python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github.brf
python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github.brf --code ueb
python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github-ebae.brf --code ebae
ls -lh epub/brf/

- name: Upload EPUB artifact
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
- name: Build BRF
run: |
pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt
python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github.brf
python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github.brf --code ueb
python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github-ebae.brf --code ebae

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
Expand All @@ -61,7 +62,9 @@ jobs:
| **EPUB** | E-readers, Apple Books, Voice Dream, DAISY players |
| **Word (.docx)** | Windows screen readers (JAWS, NVDA), Microsoft Word |
| **BRF** | Braille displays and embossers (UEB Grade 2) |
| **BRF, EBAE** | The same, in English Braille American Edition Grade 2, the US code before UEB |
files: |
epub/git-going-with-github.epub
epub/git-going-with-github.docx
epub/git-going-with-github.brf
epub/git-going-with-github-ebae.brf
30 changes: 24 additions & 6 deletions scripts/build-brf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/usr/bin/env python3
"""
Convert plain text to BRF (Braille Ready Format) using liblouis.
No TTS required — this is pure text-to-braille-dots translation.
No TTS required: this is pure text-to-braille-dots translation.

Usage: python3 build-brf.py input.txt output.brf
Usage: python3 build-brf.py input.txt output.brf [--code ueb|ebae]

--code ueb Unified English Braille, grade 2 (the default)
--code ebae English Braille American Edition, grade 2: the pre-UEB US code,
for readers who prefer it (issue #174)
"""
import sys
import louis

TABLES = {
"ueb": "en-ueb-g2.ctb",
"ebae": "en-us-g2.ctb",
}

# NABCC (North American Braille Computer Code) lookup table.
# Maps 6-dot braille cell bitmask (0-63) to ASCII character.
# bit 0=dot1, bit1=dot2, bit2=dot3, bit3=dot4, bit4=dot5, bit5=dot6
Expand All @@ -29,8 +38,17 @@ def unicode_braille_to_brf(text):


def main():
input_file = sys.argv[1] if len(sys.argv) > 1 else "/tmp/book.txt"
output_file = sys.argv[2] if len(sys.argv) > 2 else "output.brf"
args = sys.argv[1:]
code = "ueb"
if "--code" in args:
i = args.index("--code")
if i + 1 >= len(args) or args[i + 1] not in TABLES:
sys.exit("--code must be one of: " + ", ".join(TABLES))
code = args[i + 1]
del args[i:i + 2]
table = TABLES[code]
input_file = args[0] if len(args) > 0 else "/tmp/book.txt"
output_file = args[1] if len(args) > 1 else "output.brf"

with open(input_file, encoding="utf-8", errors="replace") as f:
lines = f.read().split("\n")
Expand All @@ -39,7 +57,7 @@ def main():
for line in lines:
if line.strip():
try:
braille = louis.translateString(["en-ueb-g2.ctb"], line)
braille = louis.translateString([table], line)
brf_lines.append(unicode_braille_to_brf(braille))
except Exception:
brf_lines.append(line[:80])
Expand All @@ -50,7 +68,7 @@ def main():
with open(output_file, "w", encoding="ascii", errors="replace") as f:
f.write(output)

print(f"BRF written: {len(output):,} bytes, {len(brf_lines):,} lines")
print(f"BRF written ({code.upper()}, {table}): {len(output):,} bytes, {len(brf_lines):,} lines")


if __name__ == "__main__":
Expand Down
Loading