r4victor / syncabook Goto Github PK
View Code? Open in Web Editor NEWππ§ A tool for creating ebooks with synchronized text and audio (EPUB3 with Media Overlays)
License: MIT License
ππ§ A tool for creating ebooks with synchronized text and audio (EPUB3 with Media Overlays)
License: MIT License
Hi, would like to know if your tool supports Polish language?
Is there a way to automatically include a cover in the created epub (using syncabook create
)?
Hey, bro. I did not know where else to contact you, but I found another android app which works well with EPUB3. It is called Reasily on the Google game store
Beste regards,
Audun
File "/usr/local/lib/python3.9/site-packages/afaligner/c_dtwbd_wrapper.py", line 49, in c_FastDTWBD
raise FastDTWBDError(
afaligner.c_dtwbd_wrapper.FastDTWBDError: The FastDTWDB() C function raised an error. See stderr for more details.
Hello!
I have just found your repository and it seems that this is exactly what I am looking for.
Is there a GUI available for complete beginners like me. Reading the instructions make is sound quite complicated for me.
I have some ebooks in epub format and I have an audiobook of these ebooks, where each mp3 file equals one chapter of the book.
Would your tool be able to create an ebook with synchronized text and audio when I have the files like described above ?
If yes how good/accurate is the alignment?
(Does your tool work the same way as aeneas or is it using completly different method to do the syncing?)
Have you looked at utilizing whisper AI to improve accuracy and speed https://github.com/m-bain/whisperX/
Nate
Hi, when I run the tests, I get the following result.
FAILED tests/test_create_ebook.py::test_create_ebook - AssertionError: [Message(id='MED_013', level='ERROR', location='on_the_duty_of_civil_disobedience.epub/epub/content.opf:46:100', messa...le parsing file: media overlay items must be of...
======================================================================== 1 failed, 4 passed, 176 warnings in 17.60s =========================================================================
Also, the generated synced files don't work in any Ebook reader. Audio and text work separately, but not with Media Overlays.
whenever i run syncabook -h, it shows me this-
D:\Downloads\syncabook\syncabook>syncabook -h
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\Scripts\syncabook-script.py", line 33, in
sys.exit(load_entry_point('syncabook==0.1.1', 'console_scripts', 'syncabook')())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\Scripts\syncabook-script.py", line 25, in importlib_load_entry_point
return next(matches).load()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\importlib\metadata_init_.py", line 171, in load
module = import_module(match.group('module'))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\syncabook-0.1.1-py3.10.egg\syncabook_main.py", line 3, in
from .create import create_ebook
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\syncabook-0.1.1-py3.10.egg\syncabook\create.py", line 9, in
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Right now, my process to generate files is: get an epub, covert it to a txt file, run it through syncabook, make it an epub again. By doing this, I lose a lot of information from the original epub like italicized and bold text, links, images, etc. I imagine we can instead of converting from epub to txt, convert to markdown to retain some of that info. Ofc, parsing txt for sentences isn't the same as parsing markdown, so this is probably not a straightforward feature, I imagine.
Would love to hear your thoughts on this.
Hello, I managed to get it to work when using text files. However to maintain formatting I tried to write a python script to add id attributes to existing xhtml files. It seems to work partly as when I change the page in colibrio reader or change position by pressing on a word it goes to that part in the audio. The only thing missing is the highlighting of text. Do you know of any requirement for it to work? If we managed to get it working I think it would be a nice addition to syncabook
Here is the script:
from bs4 import BeautifulSoup, NavigableString
import re
def add_ids_to_spans(html_file):
"""
This function takes a given HTML file and adds span with an unique IDs to each senetence clause. The IDs are generated by
incrementing a counter starting from 1 and formatted as "fXXX" where "XXX" is the zero-padded count. If a string of text in a
p element contains no punctuation, comma, semi-colon, exclamation mark or question mark and at least one letter, a new
span is created to wrap around the text and assigned the next ID. If the text contains a punctuation, comma, semi-colon,
exclamation mark or question mark, the text is split into separate clauses based on that and each sentence is wrapped in a
separate span with the next ID. The processed HTML file is saved with "_processed.xhtml" added to the original file name.
Parameters:
html_file (str): The path to the HTML file to be processed.
Returns:
None
"""
# Define the output file name by splitting the input file name and adding "_processed.xhtml" to it
outputfile = html_file.rsplit(".", 1)[0] + "_processed.xhtml"
# Open the input file in read mode with UTF-8 encoding
with open(html_file, "r", encoding="utf-8") as file:
# Use BeautifulSoup to parse the file
soup = BeautifulSoup(file, "lxml")
# Get all the p elements in the file
p_elements = soup.find_all("p")
# Initialize a counter for the "id" values
id_counter = 1
# Loop through each p element
for p in p_elements:
# Get all the descendants of the current "p" element. Not feeding it directly into the next loop to prevent an endless loop
children = list(p.descendants)
# Initialize a span for the case that multiple child.strings will share a span
current_span = None
# Loop through each child of the "p" element
for child in children:
# Skip if the child is a NavigableString
if isinstance(child, NavigableString):
continue
# Skip if the child has no string value. I.e. the child has multiple children of its own
elif child.string is None:
continue
elif child.string is not None:
# If there is no punctuation and there are alphabetical characters in the string, wrap the child in a new "span" tag
if not re.search(r'[:;!,?.]', child.string) and re.search(r'[a-zA-Z]', child.string):
if current_span is None:
current_span = soup.new_tag("span")
current_span["id"] = f"f{str(id_counter).zfill(3)}"
id_counter += 1
child.wrap(current_span)
# If there is alphabetical characters in the string, split the string into clauses and wrap each sentence in a new "span" tag
elif re.search(r'[a-zA-Z]', child.string):
current_span = None
sentences = re.split(r'(?<=[.?!;:,])\s+(?=[A-Za-z])', child.string)
child.clear()
for sentence in sentences:
span = soup.new_tag("span")
span["id"] = f"f{str(id_counter).zfill(3)}"
span.string = sentence + " "
child.append(span)
id_counter += 1
else:
# Printing what was not caught
print(str(child.string))
with open(outputfile, "w", encoding="utf-8") as file:
# Write the processed soup object to the output file with no extra formatting
file.write(soup.decode(formatter=None))
add_ids_to_spans(r"intputfile.xhtml")
print("process has completed successfully")
I'm getting this error:
from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.9/site-packages/markupsafe/init.py)
after I run docker run -v $(pwd):/books/mybook syncabook sync /books/mybook
it seems something to do with markupsafe 2.01 vs 2.10 from what I can find on Google. The fix to run pip install markupsafe==2.0.1 didn't work for me
any ideas?
I have been facing issues installing afaligner using pip on windows and ubuntu both.
Importantly, 'aeneas' a dependency does not install.
Hello, I have set up the syncabook
library to create ebooks with embedded audio (Epub with MediaOverlay), but the syncing functionality is not working in any of the apps I've tried so far. I followed the exact same steps mentioned under the Usage Examples heading in the same order i.e.
Step 1. syncabook download_files https://librivox.org/civil-disobedience-by-henry-david-thoreau/ civil_disobedience
Step 2. syncabook to_xhtml civil_disobedience/plaintext/ civil_disobedience/sync_text/
Step 3. syncabook sync civil_disobedience/
Step 4. syncabook create civil_disobedience/
I was successfully able to generate the .smil
files as well as the final EPUB3 ebook for Civil Disobedience book. Then, I imported the final generated EPUB3 file to different Ebook reading apps (see list below). The text looks good and the audio plays fine. However, there is no highlighting of the text along the audio. I have tried many following apps so far including the following.
It needs to be mentioned here that these apps highlight text with audio for the other books (which mostly come preloaded with these apps).
Is there something that I am missing here?
I have two questions. Does this work for books in other languages than English? Can this be used aligning lyrics with acapella song audio?
When trying to create the ebook using
syncabook create civil_disobedience
I get this error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 4: invalid continuation byte
Does anyone know the solution?
Hello, I would be very grateful if someone could help. I do not understand the error occurring after having run the sync command.
I have the xhtml and matching audio in separate folders as described. I just opened an epub as a zip file and extracted the xhtml files. That is okey right?
Best Regards,
Audun
With the imminent demise of Readium, Thorium looks to be a very good replacement reader for epubs with audio:
while using this line in cmd
docker run -v "%cd%":/ebooks/after syncabook sync /ebooks/after
docker gives me this
C:\syncabook>docker run -v "%cd%":/ebooks/after syncabook sync /ebooks/after
Calling afaligner for syncing...
Traceback (most recent call last):
File "/usr/local/bin/syncabook", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/syncabook/main.py", line 147, in main
sync(
File "/usr/local/lib/python3.8/site-packages/syncabook/sync.py", line 15, in sync
sync_map = align(
File "/usr/local/lib/python3.8/site-packages/afaligner/init.py", line 84, in align
text_paths = (os.path.join(text_dir, f) for f in sorted(os.listdir(text_dir)))
FileNotFoundError: [Errno 2] No such file or directory: '/ebooks/after/sync_text'
not sure what I'm doing wrong
syncabook dir is c:/syncabook
If I have lots of text and audio parts (e.g. 27) and I sync them all together at once, it causes a lot of out of sync and skipping issues.
But when I sync them one at a time then combine the smil
results afterwards, it doesn't seem to cause much issues, if any.
Would be nice to have an option to force one-to-one syncing.
I have been getting this error when using a docker image on raspberry pi
I created a docker container in Windows 10 as shown in the steps when installing syncabook. At the last step of 'sync' or 'create', this error pops up for the align step. I did see this error being marked as fixed in the afaligner issues, but I still face this error when going through the direct steps for syncabook
C:\Users\avina>docker run -v C:\books\mybook:/books/mybook syncabook create /books/mybook
ffmpeg version 4.3.3-0+deb11u1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mp3, from '/books/mybook/audio/pt1.mp3':
Metadata:
album : Wheel of Time 01
artist : Robert Jordan & Brandon Sanderson
comment : Dallis24β₯
encoder : Lavf54.63.104
genre : Audiobook
title : The Eye of the World pt.1
track : 1
Duration: 16:42:33.91, start: 0.025056, bitrate: 32 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, mono, fltp, 32 kb/s
Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 274x440 [SAR 100:100 DAR 137:220], 90k tbr, 90k tbn, 90k tbc (attached pic)
Metadata:
comment : Cover (front)
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/books/mybook/smil/tmp/pt1_audio.wav':
Metadata:
IPRD : Wheel of Time 01
IART : Robert Jordan & Brandon Sanderson
ICMT : Dallis24β₯
IPRT : 1
IGNR : Audiobook
INAM : The Eye of the World pt.1
ISFT : Lavf58.45.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Metadata:
encoder : Lavc58.91.100 pcm_s16le
[wav @ 0x557b1364f180] Filesize 5305573186 invalid for wav, output file will be broken
size= 5181224kB time=16:42:33.88 bitrate= 705.6kbits/s speed= 333x
video:0kB audio:5181224kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000004%
Traceback (most recent call last):
File "/usr/local/bin/syncabook", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/syncabook/main.py", line 153, in main
β SMIL files are not found. Synchronizing...
Calling afaligner for syncing...
create_ebook(
File "/usr/local/lib/python3.9/site-packages/syncabook/create.py", line 33, in create_ebook
sync(
File "/usr/local/lib/python3.9/site-packages/syncabook/sync.py", line 15, in sync
sync_map = align(
File "/usr/local/lib/python3.9/site-packages/afaligner/init.py", line 90, in align
sync_map = build_sync_map(
File "/usr/local/lib/python3.9/site-packages/afaligner/init.py", line 207, in build_sync_map
_, path = c_FastDTWBD(text_mfcc_sequence, audio_mfcc_sequence, skip_penalty, radius=radius)
File "/usr/local/lib/python3.9/site-packages/afaligner/c_dtwbd_wrapper.py", line 18, in c_FastDTWBD
c_module = ctypes.cdll[os.path.join(BASE_DIR, 'c_modules/dtwbd.so')]
File "/usr/local/lib/python3.9/ctypes/init.py", line 449, in getitem
return getattr(self, name)
File "/usr/local/lib/python3.9/ctypes/init.py", line 444, in getattr
dll = self._dlltype(name)
File "/usr/local/lib/python3.9/ctypes/init.py", line 374, in init
self._handle = _dlopen(self._name, mode)
OSError: /usr/local/lib/python3.9/site-packages/afaligner/c_modules/dtwbd.so: cannot open shared object file: No such file or directory
As far as I can tell, Syncabook itself works on windows, but if you want to make an audio-ebook something other than the 11 books in the synclibrivox repo, you need afaligner
, so itΚΌs worth mentioning that limitation of a major dependency.
Also, I can confirm that afaligner
does work on Windows with WSL, which honestly might be easier than trying to install aeneas
on Windows.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.