AutoHotkey Community

It is currently May 27th, 2012, 11:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: March 7th, 2011, 9:09 am 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
Don't know if you knew this, but I found a TTS_Google on the german forums: http://de.autohotkey.com/forum/viewtopic.php?t=8210

It basically lets you do text-to-speech using Googles TTS function, thus enabling many languages and voices. :)

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 7:50 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
@sumon:
Well, I need offline solution but thanks for a link - it's nice & useful so I'll put it in the first post. ;)

@genmce:
Quote:
Looks like "set rate" is the speed of speech.
Yes.
Quote:
Also - I don't see a pitch adjustment (perhaps I missed it), is that possible?
No.
Quote:
Each word spoken on the beat/in time with the midi clock
Imagine that pressing hotkey is in fact MIDI-IN message:
Code:
AnnaVoice := TTS_CreateVoice("Microsoft Anna")
1::TTS(AnnaVoice, "Speak", "My")
2::TTS(AnnaVoice, "Speak", "dog")
3::TTS(AnnaVoice, "Speak", "has")
4::TTS(AnnaVoice, "Speak", "fleas")
But note that you can't speak multiple phrases at the same time. No overlapping. Unless you use AutoHotkey.dll


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 8:24 am 
Offline

Joined: March 7th, 2011, 2:59 am
Posts: 151
This was one of the most mind-boggling scripts of all time! :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2011, 8:31 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2011, 4:02 am 
Offline

Joined: July 10th, 2011, 11:06 pm
Posts: 13
Location: United States
Our 8 year old daughter absolutely loves playing with this program and I figured others would find it entertaining/helpful.

Code:
; Instantly read text aloud upon pressing Enter.

/*
Intended Audience:
   * Young children who get a kick out of playing with Text-to-Speech or who are learning to spell.
   * Speech impaired individuals who want to be able to use TTS at near conversational speeds for communication.
   * Anonymous callers.
   * Prank callers.

Prerequisits:
   * AutoHotkey_L available at http://www.autohotkey.net/~Lexikos/AutoHotkey_L/. This code is not compatible with AutoHotkey Basic.
   * Create one text file named "Text-to-Speech Male.txt" and one named "Text-to-Speech Female.txt". It does not matter where the files are located.
   * SAPI voice(s) preinstalled. The voice "Microsoft Anna" should be preinstalled on Vista and Windows 7 operating systems so at least the female voice should work by default on most modern systems. "Microsoft Sam" is the default voice for Windows XP but "Microsoft Sam," "Microsoft Mike," and "Microsoft Mary" do not work on Windows Vista and later. NextUp.com is a convenient place to purchase additional and/or better voices but you may have to purchase one of their programs to be able to use the voices. See http://www.nextup.com/TextAloud/SpeechEngine/voices.html
   
Instructions:
   See what TTS voices you have available on your system and see what they are called by executing the following script:
      ; TTS Voice List by Learning one
      Voice := ComObjCreate("SAPI.SpVoice")
      MsgBox % TTS(Voice, "GetVoices")
      ExitApp
   Customize the names of the TTS voices in the following script
   Execute the script.
   Open one or both of the text files created above.
   Type something into one of the text files.
   Press Enter
   The text will automatically be read.
   Press Enter again to repeat the speech.
   Start typing while text is highlighted to replace with a new phrase.
*/

; C U S T O M I Z E   T H E   F O L L O W I N G   T T S   N A M E S :
; (These should be identical to one of the voices listed in TTS Voice List script from the instructions.)

MaleVoice := TTS_CreateVoice("ScanSoft Lee_Full_22kHz") ; This is a great sounding, premium Austrialian voice. See http://www.nextup.com/TextAloud/SpeechEngine/voices.html#Nuance
FemaleVoice := TTS_CreateVoice("Microsoft Anna") ; Beginning with Windows Vista and Windows 7, Microsoft Anna is the default English voice.

; E N D  O F  C U S T O M I Z A T I O N

; Text reader for male voice
SetTitleMatchMode , 2 ; This allows WinWaitActive/#IfWinActive to match a part of the window title rather than the whole thing.
#IfWinActive , Text-to-Speech Male ; This causes the hotkey to only work in a window titled Text-to-Speech Male
Enter::TTS(MaleVoice, "ToggleSpeak", gst()) ; Type some text and press Enter to have it spoken.
Return

; Text reader for female voice
SetTitleMatchMode , 2 ; This allows WinWaitActive/#IfWinActive to match a part of the window title rather than the whole thing.
#IfWinActive , Text-to-Speech Female ; This causes the hotkey to only work in a window titled Text-to-Speech Female
Enter::TTS(FemaleVoice, "ToggleSpeak", gst()) ; Type some text and press Enter to have it spoken by Microsoft Anna.
Return

; F U N C T I O N S :
; -------------------------------------------
; GetSelectedText Function by Learning one
gst() {   
   Send , ^a^c
   ClipWait , 0.1
   ToReturn := Clipboard, Clipboard := ClipboardBackup
   if !IsClipEmpty
   ClipWait, 0.5, 1
   Return ToReturn
}

; TTS (Text-to-Speech) Function
TTS(oVoice, command, param1="", param2="") {      ; by Learning one. For AHK_L. Thanks: jballi, Sean, Frankie.
   ; AHK forum location:   www.autohotkey.com/forum/topic57773.html
   ; Read more:         msdn.microsoft.com/en-us/library/ms723602(v=VS.85).aspx, www.autohotkey.com/forum/topic45471.html
   static CommandList := "ToggleSpeak,Speak,SpeakWait,Pause,Stop,SetRate,SetVolume,SetVoice,GetVoices,GetStatus,GetCount,SpeakToFile"
   if command not in %CommandList%
   {
      MsgBox, 16, TTS() error, "%command%" is not valid command.
      return
   }
   if command = ToggleSpeak   ; speak or stop speaking
   {
      Status := oVoice.Status.RunningState
      if Status = 1   ; finished
      oVoice.Speak(param1,0x1)   ; speak asynchronously
      Else if Status = 0   ; paused
      {
         oVoice.Resume
         oVoice.Speak("",0x1|0x2)   ; stop
         oVoice.Speak(param1,0x1)   ; speak asynchronously
      }
      Else if Status = 2   ; reading
      oVoice.Speak("",0x1|0x2)   ; stop
   }
   Else if command = Speak      ; speak asynchronously
   {
      Status := oVoice.Status.RunningState
      if Status = 0   ; paused
      oVoice.Resume
      oVoice.Speak("",0x1|0x2)   ; stop
      oVoice.Speak(param1,0x1)   ; speak asynchronously
   }
   Else if command = SpeakWait      ; speak synchronously
   {
      Status := oVoice.Status.RunningState
      if Status = 0   ; paused
      oVoice.Resume
      oVoice.Speak("",0x1|0x2)   ; stop
      oVoice.Speak(param1,0x0)   ; speak synchronously
   }
   Else if command = Pause   ; Pause toggle
   {
      Status := oVoice.Status.RunningState
      if Status = 0   ; paused
      oVoice.Resume
      else if Status = 2   ; reading
      oVoice.Pause
   }
   Else if command = Stop
   {
      Status := oVoice.Status.RunningState
      if Status = 0   ; paused
      oVoice.Resume
      oVoice.Speak("",0x1|0x2)   ; stop
   }
   Else if command = SetRate
   oVoice.Rate := param1      ; rate (reading speed): param1 from -10 to 10. 0 is default.
   Else if command = SetVolume
   oVoice.Volume := param1      ; volume (reading loudness): param1 from 0 to 100. 100 is default
   Else if command = SetVoice
   {
      Loop, % oVoice.GetVoices.Count
      {
         Name := oVoice.GetVoices.Item(A_Index-1).GetAttribute("Name")   ; 0 based
         If (Name = param1)
         {
            DoesVoiceExist = 1
            break
         }
      }
      if !DoesVoiceExist
      {
         MsgBox,64,, Voice "%param1%" does not exist.
         return
      }
      While   !(oVoice.Status.RunningState = 1)
      Sleep, 20
      oVoice.Voice := oVoice.GetVoices("Name=" param1).Item(0) ; set voice to param1
   }
   Else if command = GetVoices
   {
      param1 := (param1 = "") ? "`n" : param1      ; param1 as delimiter
      Loop, % oVoice.GetVoices.Count
      {
         Name := oVoice.GetVoices.Item(A_Index-1).GetAttribute("Name")   ; 0 based
         VoiceList .= Name param1
      }
      Return RTrim(VoiceList,param1)
   }
   Else if command = GetStatus
   {
      Status := oVoice.Status.RunningState
      if StatusNum = 0 ; paused
      Return "paused"
      Else if StatusNum = 1 ; finished
      Return "finished"
      Else if StatusNum = 2 ; reading
      Return "reading"
   }
   else if command = GetCount
   return oVoice.GetVoices.Count
   Else if command = SpeakToFile   ; param1 = TextToSpeak,    param2 = OutputFilePath
   {
      oldAOS := oVoice.AudioOutputStream
      oldAAOFCONS := oVoice.AllowAudioOutputFormatChangesOnNextSet
      oVoice.AllowAudioOutputFormatChangesOnNextSet := 1   
     
      SpStream := ComObjCreate("SAPI.SpFileStream")
      FileDelete, % param2   ; OutputFilePath
      SpStream.Open(param2, 3)
      oVoice.AudioOutputStream := SpStream
      TTS(oVoice, "SpeakWait", param1)
      SpStream.Close()
      oVoice.AudioOutputStream := oldAOS
      oVoice.AllowAudioOutputFormatChangesOnNextSet := oldAAOFCONS
   }
}   

TTS_CreateVoice(VoiceName="", VoiceRate="", VoiceVolume="") {      ; by Learning one. For AHK_L.
   oVoice := ComObjCreate("SAPI.SpVoice")
   if !(VoiceName = "")
   TTS(oVoice, "SetVoice", VoiceName)
   if VoiceRate between -10 and 10
   oVoice.Rate := VoiceRate      ; rate (reading speed): param1 from -10 to 10. 0 is default.
   if VoiceVolume between 0 and 100
   oVoice.Volume := VoiceVolume   ; volume (reading loudness): param1 from 0 to 100. 100 is default
   return oVoice
}


Remington


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2011, 5:26 am 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 2:28 am 
Offline

Joined: November 14th, 2008, 4:02 pm
Posts: 7
Location: Ft. Lewis
That script is really cool Remington! I'm not much of a scripter / programmer, so I'm trying to figure it all out.

What would I need to simply speak a phrase set by the script its self, without any custom voice options, clipboard management or any of that?

I was totally unaware of AutoHotkey_L, so I'm lost all over again.

_________________
I have no idea what I'm doing, but its AWESOME!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 3:26 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
In AHK_L TTS is a one-liner
Code:
ComObjCreate("SAPI.SpVoice").Speak("Testing one two three")

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 3:35 am 
Offline

Joined: November 14th, 2008, 4:02 pm
Posts: 7
Location: Ft. Lewis
Holy crap, thanks! So something like this would do what I need:

Code:
ComObjCreate("SAPI.SpVoice").Speak("%string%")


That would make eyes-free feedback so much easier. I guess I need to do some serious reading on this _L situation.

_________________
I have no idea what I'm doing, but its AWESOME!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 4:48 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
You should read up on expressions: http://d.ahk4.me/Variables#Expressions
Basically remove the "%%" around the variable.
Code:
pVoice := ComObjCreate("SAPI.SpVoice")
pVoice.Speak("Literal string")
pVoice.Speak(Variable)
Note how I stored the object in a variable -- it will run faster with multiple things to "say" since it won't keep re-creating.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2012, 9:12 pm 
Offline

Joined: February 10th, 2012, 8:19 am
Posts: 2
Hi All,

How can I use other SAPI voices? the script above use only SAPI voice and I have SAPI5 and SAPI 4 voices too...

Thanls!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Found the problem
PostPosted: February 11th, 2012, 3:59 pm 
if I run the script above using the x64 execution, its see only 1 TTS

BUT if i run the script using the x86, then I see the real number that installed on my system...

Thanks to all on the great script...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2012, 7:16 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
hqworp wrote:
How can I use other SAPI voices?
First you'll have to download and install additional SAPI voices. I posted links to some free SAPI voices here.

* * *

:arrow: TTS() and TTS_CreateVoice() updated
The new feature is that now user can easily change voice's pitch. I also posted 2 new examples.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2012, 2:00 am 
Offline

Joined: December 26th, 2011, 11:14 pm
Posts: 6
I too am having problem with memory overuse.
After speaking, the script won't clear memory.
Could you help me, Learning One?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2012, 10:23 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Hi daveclark,

when I run example 1 script, it initially takes 2780 K of memory. After pressing F1, it takes 9250 K, and it's not increasing after that. If you have similar results - that's OK.
Try this simple script:
Code:
oVoice := ComObjCreate("SAPI.SpVoice")
MsgBox, Check memory usage now and after you press OK.
oVoice.Speak("Automate almost anything by sending keystrokes and mouse clicks.",0x0)
Similar thing as in example 1 happens here as well - before pressing OK, it takes 2780 K, and after pressing OK, it takes 9070 K.
So, after calling Speak method, memory usage will increase. If you think that's not OK, than I think you'll have to contact Lexikos or maybe Microsoft.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: nomissenrojb and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group