ePub 2 TTS (Text To Speech) this script will read e-books in the format of ePub using your computer sound card/ speakers.

You can get over 45,000 book from Project Gutenberg or other places around the Internet.

Let’s explain a bit:

$read = New-Object -com SAPI.SpVoice

creates an object for the SpVoice interface read all about it.

Then the Get-FileName simply uses the .NET open file dialog to allow the user to select the epub e-book file.

Next step I copy the file and add the .zip extension to it, then unZip it.

Now the next part is inside the .epub files I find the location of the book files and then start playing the book.

For each line I read I save the progress to a file so if you will stop it you can get back to where you stopped.

I’m sure there’s a lot more to do here, but I think it’s nice.

I’ve tried it with several e-books;

Alice in Wonderland

Don Winslow of the Navy

Let me know how it works for you 😀 enjoy.

$read = New-Object -com SAPI.SpVoice function readBook() { param( [string]$book, [string]$bookPath, [int]$lineNumber = 0 ) $data = Get-Content $book for([int]$i=$lineNumber;$i -lt $data.Count;$i++) { Set-Content -Path $bookPath"\progress.txt" -Value ($book+","+$i) $line = $data[$i] if($line.Contains("<title>")) { $line = $line -Replace "<.+?>","" $read.Speak($line) } if($line.contains("<p")){ $line = $line -Replace "<.+?>","" $read.Speak($line) } } Set-Content -Path $bookPath"\progress.txt" -Value ("") } Function Get-FileName() { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog #$OpenFileDialog.initialDirectory = "c:\" $OpenFileDialog.filter = "ePub files (*.epub)| *.epub" $OpenFileDialog.ShowDialog() | Out-Null return $OpenFileDialog.filename } function unzip() { param ( [string]$file, [string]$dest ) $shell = new-object -com shell.application $zip = $shell.NameSpace($file) foreach($item in $zip.items()) { $shell.Namespace($dest).copyhere($item) } } $epubFile = Get-FileName $file = get-item $epubFile if(!(Test-Path($file.DirectoryName+"\"+$file.Name+".zip"))) { $zipFile = $file.DirectoryName+"\"+$file.Name+".zip" $file.CopyTo($zipFile) } $destination = $file.DirectoryName+"\"+$file.Name.Replace($file.Extension,"") if(!(Test-Path($destination))) { md $destination unzip -file $zipFile -dest $destination } [xml]$container = Get-Content $destination"\META-INF\container.xml" $contentFilePath = $container.container.rootfiles.rootfile."full-path" [xml]$content = Get-Content $destination"\"$contentFilePath $tmpPath = Get-Item $destination"\"$contentFilePath $bookPath = $tmpPath.DirectoryName $progress = $null foreach($item in $content.package.manifest.Item) { if($item."media-type" -eq "application/xhtml+xml") { if(Test-Path($bookPath+"\progress.txt")) { $progress = Get-Content $bookPath"\progress.txt" $progress = $progress.Split(",") } $bookFileName = $item.href if($progress.Count -eq 2) { if($progress[0] -eq $bookPath+"\"+$bookFileName) { readBook -book $bookPath"\"$bookFileName -bookPath $bookPath -lineNumber $progress[1] } } else { readBook -book $bookPath"\"$bookFileName -bookPath $bookPath } } }