Skip to content

Commit 50e2444

Browse files
taylorarndtCopilot
andcommitted
fix: use python3-louis for BRF — direct text-to-braille, zero TTS
Replace file2brl with Python louis library: - pandoc extracts plain text from EPUB - louis.translateString with en-ueb-g2.ctb does Grade 2 braille - NABCC lookup table converts Unicode braille to ASCII BRF format - No DAISY Pipeline, no TTS, no web service required Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5dbfaa9 commit 50e2444

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

.github/workflows/build-epub.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,49 @@ jobs:
3535
run: node scripts/build-epub.js
3636

3737
- name: Install liblouis (braille translator — no TTS needed)
38-
run: sudo apt-get install -y liblouisutdml-bin
38+
run: sudo apt-get install -y liblouis-bin python3-louis
3939

4040
- name: Convert EPUB to BRF (Braille — no TTS required)
4141
continue-on-error: true
4242
run: |
4343
mkdir -p epub/brf
44-
# --standalone produces a single well-formed HTML doc; file2brl requires valid XML
45-
pandoc epub/git-going-with-github.epub -f epub -t html --standalone -o /tmp/book.html
46-
file2brl /tmp/book.html epub/brf/git-going-with-github.brf || echo "BRF conversion failed"
47-
ls -lh epub/brf/ || echo "No BRF output produced"
44+
# Pandoc extracts plain text from EPUB
45+
pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt
46+
# Python + liblouis translates text → Grade 2 braille → NABCC ASCII BRF (no TTS, pure text)
47+
python3 - <<'EOF'
48+
import louis, sys
49+
50+
NABCC = ' A1B\'K2L@CIF/MSP"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)='
51+
52+
def to_brf(ub):
53+
out = []
54+
for ch in ub:
55+
c = ord(ch)
56+
if 0x2800 <= c <= 0x283F:
57+
out.append(NABCC[c - 0x2800])
58+
else:
59+
out.append(ch if c < 128 else ' ')
60+
return ''.join(out)
61+
62+
with open('/tmp/book.txt', encoding='utf-8', errors='replace') as f:
63+
lines = f.read().split('\n')
64+
65+
brf = []
66+
for line in lines:
67+
if line.strip():
68+
try:
69+
brf.append(to_brf(louis.translateString(['en-ueb-g2.ctb'], line)))
70+
except Exception:
71+
brf.append(line[:80])
72+
else:
73+
brf.append('')
74+
75+
out = '\n'.join(brf)
76+
with open('epub/brf/git-going-with-github.brf', 'w', encoding='ascii', errors='replace') as f:
77+
f.write(out)
78+
print(f"BRF written: {len(out)} bytes, {len(brf)} lines")
79+
EOF
80+
ls -lh epub/brf/
4881

4982
- name: Upload EPUB artifact
5083
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)