Advertisement
ekostadinov

Text-To-Speech

Aug 18th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.83 KB | None | 0 0
  1. function GetTTS($myText)
  2. {
  3.     $url = 'http://www.text2speech.org/'
  4.     $ie = New-Object -com 'InternetExplorer.Application'
  5.     $ie.visible = $true
  6.     $ie.navigate($url)
  7.     Start-Sleep -Seconds 3
  8.     $doc  = $ie.document
  9.     #wait untill ready
  10.     while($doc -eq $null)
  11.     {
  12.         Start-Sleep -Seconds 1
  13.         $doc  = $ie.document
  14.     }
  15.     #input text
  16.     $textArea = $doc.getElementsByName('speech')
  17.     $textArea.item(0).value = $myText
  18.     #select voice
  19.     $voices = $doc.getElementsByName('voice')
  20.     $voices.item(0).item(1).selected = $true
  21.     #covenrt to speech
  22.     $convertBtn = $doc.getElementsByName('make_audio')
  23.     $convertBtn.item(0).click()
  24.     #wait untill audio file is ready
  25.     $mp3 = $doc.getElementsByTagName('a') | where InnerText -Match 'MP3 file' | select -Property href  
  26.     while($mp3 -eq $null)
  27.     {
  28.         Start-Sleep -Seconds 5
  29.         $mp3 = $doc.getElementsByTagName('a') | where InnerText -Match 'MP3 file' | select -Property href
  30.     }
  31.     #$mp3.click()
  32.     $mp3Str = [System.String]$mp3
  33.     #download mp3 audio file
  34.     DownloadMP3 -mp3Url $mp3Str  
  35. }
  36. function DownloadMP3($mp3Url)
  37. {
  38.     #clear the url string
  39.     $dummyStr = ''
  40.     for($c=7; $c -le $mp3Str.Length - 2; $c++)
  41.     {
  42.         $dummyStr += $mp3Str[$c]
  43.     }
  44.     $wc = New-Object System.Net.WebClient
  45.     $date = Get-Date
  46.     $date = "{0:dd_MM_yyyy-HH_MM_ss}" -f [datetime]$date
  47.     $file = 'C:\Users\evgeni.kostadinov\Desktop\TTScrawler\file' + $date.ToString() +'.mp3'
  48.     $wc.DownloadFile($dummyStr, $file)  
  49. }
  50. $text = Get-Content 'C:\Users\evgeni.kostadinov\Desktop\TTScrawler\text.txt'
  51.  #max length can be 5K chars
  52.  $textStr = [System.String]$text
  53. if($textStr.Length -ge 4000)
  54. {
  55.    wite-host 'The text Length is > 5000(4k). The webservice CAN NOT work with it!'
  56. }
  57. else{
  58.     GetTTS -myText $text
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement