-
Notifications
You must be signed in to change notification settings - Fork 0
/
epub_to_mp3.ps1
51 lines (39 loc) · 1.66 KB
/
epub_to_mp3.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Clear the screen
Clear-Host
# Load setup.json content
$setupJsonPath = Join-Path -Path $Global:currentPath -ChildPath "setup.json"
$setupConfig = Get-Content -Path $setupJsonPath -Raw -Encoding UTF8 | ConvertFrom-Json
$Global:currentPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
# Accessing the values
$Global:defaultLibraryPath = $setupConfig.default_library_path
$Global:ebookPath = $setupConfig.default_ebook_path
$EpubToTxtScriptPath = "$Global:currentPath\epub_to_txt.ps1"
. $EpubToTxtScriptPath
$TxtToMp3ScriptPath = "$Global:currentPath\txt_to_mp3.ps1"
. $TxtToMp3ScriptPath
function GetEbookPath {
[CmdletBinding()]
$dialog = New-Object System.Windows.Forms.OpenFileDialog
$dialog.InitialDirectory = $Global:defaultLibraryPath
$dialog.Filter = "ePub files (*.epub)|*.epub"
$result = $dialog.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
return $dialog.FileName
}
Write-Warning "No eBook selected. Exiting script."
exit
}
# Main Script Execution
Initialize
# Setup and User Prompts
if (-not $Global:ebookPath) {
$Global:ebookPath = GetEbookPath
}
# Convert Epub to Txt and allow user to edit
ConvertEpubToTxtAndEdit
# Prepare paths for text-to-audio conversion
$ebookName = [System.IO.Path]::GetFileNameWithoutExtension($Global:ebookPath)
$inputFolderPath = Join-Path -Path $Global:currentPath -ChildPath "extracted_chapters\$ebookName"
$outputFolderPath = Join-Path -Path $Global:currentPath -ChildPath "output\$ebookName"
# Convert text files to audio
ConvertTxtToMP3AndEdit -InputFolderPath $inputFolderPath -OutputFolderPath $outputFolderPath -DesiredVoiceName $Global:voiceName