Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetTTS($myText)
- {
- $url = 'http://www.text2speech.org/'
- $ie = New-Object -com 'InternetExplorer.Application'
- $ie.visible = $true
- $ie.navigate($url)
- Start-Sleep -Seconds 3
- $doc = $ie.document
- #wait untill ready
- while($doc -eq $null)
- {
- Start-Sleep -Seconds 1
- $doc = $ie.document
- }
- #input text
- $textArea = $doc.getElementsByName('speech')
- $textArea.item(0).value = $myText
- #select voice
- $voices = $doc.getElementsByName('voice')
- $voices.item(0).item(1).selected = $true
- #covenrt to speech
- $convertBtn = $doc.getElementsByName('make_audio')
- $convertBtn.item(0).click()
- #wait untill audio file is ready
- $mp3 = $doc.getElementsByTagName('a') | where InnerText -Match 'MP3 file' | select -Property href
- while($mp3 -eq $null)
- {
- Start-Sleep -Seconds 5
- $mp3 = $doc.getElementsByTagName('a') | where InnerText -Match 'MP3 file' | select -Property href
- }
- #$mp3.click()
- $mp3Str = [System.String]$mp3
- #download mp3 audio file
- DownloadMP3 -mp3Url $mp3Str
- }
- function DownloadMP3($mp3Url)
- {
- #clear the url string
- $dummyStr = ''
- for($c=7; $c -le $mp3Str.Length - 2; $c++)
- {
- $dummyStr += $mp3Str[$c]
- }
- $wc = New-Object System.Net.WebClient
- $date = Get-Date
- $date = "{0:dd_MM_yyyy-HH_MM_ss}" -f [datetime]$date
- $file = 'C:\Users\evgeni.kostadinov\Desktop\TTScrawler\file' + $date.ToString() +'.mp3'
- $wc.DownloadFile($dummyStr, $file)
- }
- $text = Get-Content 'C:\Users\evgeni.kostadinov\Desktop\TTScrawler\text.txt'
- #max length can be 5K chars
- $textStr = [System.String]$text
- if($textStr.Length -ge 4000)
- {
- wite-host 'The text Length is > 5000(4k). The webservice CAN NOT work with it!'
- }
- else{
- GetTTS -myText $text
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement