patrickenfuego / Chapterize-Audiobooks

Split a single, monolithic mp3 audiobook file into chapters using Machine Learning and ffmpeg.
Apache License 2.0
93 stars 16 forks source link

When I run the script, I get a syntax error in line 40, to do with vosk_link #3

Closed theClubHopper closed 1 year ago

theClubHopper commented 1 year ago

Installed on my Windows 10 machine, with python3 and ffmpeg etc up to date. When I run any command involving chapterize_ab.py (including "-h"), I get the following error:

File "C:\dev\chapterize-audiobooks-main\chapterize_ab.py", line 40 vosk_link = f"[link={vosk_url}]this link[/link]" ^ SyntaxError: invalid syntax

Any ideas why?

theClubHopper commented 1 year ago

It took me a while to figure out what I was doing wrong - the reported error was a result of me accidentally omitting the required 'python' command beginning my line of Powershell input. Stupid mistake!

I also discovered that in Powershell, for 'security reasons', one can't natively run a script from the directory that the script is in. Seems counter intuitive to me but that's the way it is. So, I finally got 'python .\Chapterize-audiobooks-main\chapterize_ab.py -h' to work, but then the script soon stopped with multiple errors --at the vosk model download/check part of the process.

The 'en-us' 'small' model was already installed, and reinstalling everything from scratch did not help. I rechecked my PATH environment settings, good. And yes, I'd seen your message at 'permission denied' at the bottom of the instructions page here, and although I was getting the same message, this was not the same reason.

I eventually realized the script expected to find the 'model' folder as a subfolder of the one the script was being run from - but as it wasn't due to Powershell's limitation, it stopped with an error message. My solution was to navigate to the Chapterize-audiobooks-main directory in Powershell and execute the following command: Set-Location .\Chapterize-Audiobooks-main\

After this, from that directory, I was able to run the command: "python chapterize_ab.py 'D:\Audiobooks\MyAudioBook.mp3' and it ran, and completed, successfully. I'm impressed with the result!

It did however pick up a false chapter break that messed up subsequent chapter numbering (my audiobook contained a sentence with the phrase "that particular chapter"). I'd hoped to find a script-created timecodes file (like a cue file) that listed ONLY all the found chapter breaks, and that the incorrect split could be manually removed and the script run again with splits based on this file, but there was none in any directory I could find.

The issue was easily fixed by manually adding the phrase to the exclusions at the end of the models.py file and re-running chapterize_ab.py, which I was pleased to see completed quickly this time as the audio-to-text conversion was already done.

Related, the other thing that wasn't ideal was the my audiobook has a preamble of approximately 1 minute before "Chapter 1" is said, and the script was recording Chapter 1 as starting at 00:00:00. Again, this would have been easy to fix if a chapter-breaks-only timecodes file had been created - but I fixed my problem by editing chapterize_ab.py's 'parse_timecodes' section, adding a 'time_dict' entry setting 00:00:00 to chapter_type 'Prologue' and appending it to the time_dict immediately before the 'for' loop.

patrickenfuego commented 1 year ago

Hey there @theClubHopper! So sorry for the late response, my github notifications are inundated with security advisories for one of my old private website repositories lol.

I'm happy to hear you figured it out, AND you found a new excluded phrase! Awesome! That's exactly the type of feedback I want to get.

I also really like your idea of generating a cue file - I'll get working on that and should have it out soon (as time permits).

As for the script directory, yes that is a limitation unfortunately - unless the model directory is added to system PATH (which I thought about doing, but I hate using environment variables for hacks like that), the OS isn't context aware in that case. So it's best to run it from the local directory to remove any path resolution errors (should be the same for defaults.toml too, if you use that). There are some tricks around this, but at the time I was concerned with getting the core functionality implemented. I'll revisit that one as well. Although I'm curious why you had to run Set-Location once you were already in the repo directory - that's unusual and isn't something I have to do - as long as you cd/Set-Location into the main directory, everything should resolve properly because the script just looks for a directory model relative to the script file (unless I'm misunderstanding).

As for the preambles, that one was tough because there are so many ways a book can start - Prologue is the most obvious, but there are many others. The script essentially looks for those "keywords" to create a chapter marker, so if "Prologue" wasn't picked up in the speech-to-text, then it will assume Chapter 1 is the start. If you could send me the keyword (whether it be "Forward", "Author's Note", etc.) I can start compiling a list for better parsing in the future.

Keep using it and let me know if you find any more phrases, or come up with some new ideas 😄

patrickenfuego commented 1 year ago

As an aside (if I'm understanding you correctly), you can fix that PowerShell issue by running the following command as an administrator:

Set-ExecutionPolicy remoteSigned
theClubHopper commented 1 year ago

Cool. Thanks for that!


From: patrickenfuego @.> Sent: Monday, January 16, 2023 7:24:54 PM To: patrickenfuego/Chapterize-Audiobooks @.> Cc: theClubHopper @.>; Mention @.> Subject: Re: [patrickenfuego/Chapterize-Audiobooks] When I run the script, I get a syntax error in line 40, to do with vosk_link (Issue #3)

As an aside, you can fix that PowerShell issue by running the following command as an administrator:

Set-ExecutionPolicy remoteSigned

— Reply to this email directly, view it on GitHubhttps://github.com/patrickenfuego/Chapterize-Audiobooks/issues/3#issuecomment-1384694381, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARZ2EAQ6DDZRRO4SW3Q5WZLWSXRFNANCNFSM6AAAAAASYQGHEE. You are receiving this because you were mentioned.Message ID: @.***>

theClubHopper commented 1 year ago

re: preamble and keywords – In that particular audiobook I was splitting, the preamble had no real identifiable keywords – even the dedication and epigraph were unannounced. So out of curiosity, I checked some other audiobooks I have and found that of the ones introducing the first chapter using the words “Chapter One” (rather than just “One” like so many unfortunately do), one book’s preamble was followed by an announced “Introduction” consisting of multiple read pages prior to the announcement of “Chapter One”. So that would be a good keyword to split on.

By the way, the only other suggestion I have is that numbers (track & chapter) are perhaps better written in 2-digit– format ie “01” vs “1” and so on. Windows natively sorts things properly but I was surprised to find that not every utility or app I threw my mp3s into sorted them properly, resulting in ‘1,10,11” and “19,2,20” etc.

From: the ClubHopper @.> Sent: Tuesday, January 17, 2023, 00:47 To: patrickenfuego/Chapterize-Audiobooks @.>; patrickenfuego/Chapterize-Audiobooks @.> Cc: Mention @.> Subject: Re: [patrickenfuego/Chapterize-Audiobooks] When I run the script, I get a syntax error in line 40, to do with vosk_link (Issue #3)

Cool. Thanks for that!

From: patrickenfuego @.> Sent: Monday, January 16, 2023 7:24:54 PM To: patrickenfuego/Chapterize-Audiobooks @.> Cc: theClubHopper @.>; Mention @.> Subject: Re: [patrickenfuego/Chapterize-Audiobooks] When I run the script, I get a syntax error in line 40, to do with vosk_link (Issue #3)

As an aside, you can fix that PowerShell issue by running the following command as an administrator:

Set-ExecutionPolicy remoteSigned

— Reply to this email directly, view it on GitHubhttps://github.com/patrickenfuego/Chapterize-Audiobooks/issues/3#issuecomment-1384694381, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARZ2EAQ6DDZRRO4SW3Q5WZLWSXRFNANCNFSM6AAAAAASYQGHEE. You are receiving this because you were mentioned.Message ID: @.***>

patrickenfuego commented 1 year ago

@theClubHopper

By the way, the only other suggestion I have is that numbers (track & chapter) are perhaps better written in 2-digit– format ie “01” vs “1”

Interesting you bring that up, originally, I had used 2-digit numbers. I shall reimplement them 😃

You make a good point about some books excluding "Chapter" and instead just announcing the numerical identifier. I'll have to think of a way around that without raising false positives 🤔