Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;TextToSpeechVoicesMenu.
- ; Class TTS by evilC
- ; Based on code 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, www.autohotkey.com/forum/topic83162.html
- ;I have made just only the menu and added in this menu to include many common languages. The languages not used can be replaced or removed.
- F12:: ; i.e. press F12 hotkey to show the menu. ;press Gaming Mouse XButton1 or ScrollLock to read selected text aloud
- s := new TTS()
- ;Speech Engines Menu
- ;Menu, MenuName, Add, Voice Name, FunctionToBeExecuted(WithoutSpaces)
- Menu, TTS, Add, ; Add a separator line.
- Menu, Arabic, Add, Laila, Laila
- Menu, Armenian, Add, Armenian, Armenian
- Menu, English, Add, Steven, Steven
- Menu, English, Add, Eric, Eric
- Menu, French, Add, Juliette, Juliette
- Menu, French, Add, Hortense, Hortense
- Menu, Georgian, Add, Georgian, Georgian
- Menu, German, Add, Stefan, Stefan
- Menu, German, Add, Hedda, Hedda
- Menu, Greek, Add, Greek, Greek
- Menu, Greek, Add, Melina, Melina
- Menu, Hebrew, Add, Carmit, Carmit
- Menu, Hindi, Add, Hindi, Hindi
- Menu, Hindi, Add, Lekha, Lekha
- Menu, Italian, Add, Silvia, Silvia
- Menu, Italian, Add, Lucia, Lucia
- Menu, Latin, Add, Latin, Latin
- Menu, Russian, Add, Katya, Katya
- Menu, Russian, Add, Olga, Olga
- Menu, Persian, Add, Persian, Persian
- Menu, Spanish, Add, Isabel, Isabel
- Menu, Spanish, Add, Helena, Helena
- Menu, Chinese, Add, Li-li, Li-li
- Menu, Chinese, Add, HuiHui, HuiHui
- Menu, Japanese, Add, Haruka, Haruka
- Menu, Japanese, Add, Kyoko, Kyoko
- Menu, Korean, Add, Yuna, Yuna
- Menu, Korean, Add, Heami, Heami
- ; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
- Menu, TTS, Add, Arabic, :Arabic
- Menu, TTS, Add, Armenian, :Armenian
- Menu, TTS, Add, English, :English
- Menu, TTS, Add, French, :French
- Menu, TTS, Add, Georgian, :Georgian
- Menu, TTS, Add, German, :German
- Menu, TTS, Add, Greek, :Greek
- Menu, TTS, Add, Hebrew, :Hebrew
- Menu, TTS, Add, Hindi, :Hindi
- Menu, TTS, Add, Italian, :Italian
- Menu, TTS, Add, Latin, :Latin
- Menu, TTS, Add, Russian, :Russian
- Menu, TTS, Add, Persian, :Persian
- Menu, TTS, Add, Spanish, :Spanish
- Menu, TTS, Add, Chinese, :Chinese
- Menu, TTS, Add, Japanese, :Japanese
- Menu, TTS, Add, Korean, :Korean
- Menu, TTS, Add, ; Add a separator line.
- Menu, TTS, Show
- s.Speak(gst()) ; select some text and press Ctrl+ScrollLock to test Speak()
- XButton1::s.Speak(gst())
- ScrollLock::s.Speak(gst())
- s.SetVoice("")
- ;Applications
- English:
- Steven:
- s.SetVoice("Steven") ;PUT HERE YOUR OWN TTS VOICE NAME
- return
- Eric:
- s.SetVoice("IVONA 2 Eric OEM") ;PUT HERE YOUR OWN TTS VOICE NAME
- return
- Russian:
- Katya:
- s.SetVoice("Vocalizer Expressive Katya Harpo 22kHz") ;PUT HERE YOUR OWN TTS VOICE NAME
- return
- Olga:
- s.SetVoice("Olga") ;Russian
- return
- Latin:
- s.SetVoice("eSpeak-la+f2") ;Latin
- return
- Armenian:
- s.SetVoice("eSpeak-hy+f2") ;Armenian
- return
- Carmit:
- s.SetVoice("Vocalizer Expressive Carmit Harpo 22kHz") ;Hebrew
- return
- Greek:
- s.SetVoice("eSpeak-grc+f2") ;Ancient Greek
- return
- Melina:
- s.SetVoice("Vocalizer Expressive Melina Harpo 22kHz") ;New Greek
- return
- Georgian:
- s.SetVoice("eSpeak-ka+f2") ;Georgian
- return
- French:
- Juliette:
- s.SetVoice("Juliette") ;French
- return
- Hortense:
- s.SetVoice("Hortense, fr-FR MS") ;French
- return
- German:
- Stefan:
- s.SetVoice("Stefan") ;German
- return
- Hedda:
- s.SetVoice("Hedda, de-DE MS") ;German
- return
- Italian:
- Silvia:
- s.SetVoice("ScanSoft Silvia_Full_22kHz") ;Italian
- return
- Lucia:
- s.SetVoice("Lucia, it-IT MS") ;Italian
- return
- Spanish:
- Isabel:
- s.SetVoice("ScanSoft Isabel_Full_22kHz") ;Spanish
- return
- Helena:
- s.SetVoice("Helena, es-ES MS") ;Spanish
- return
- Laila:
- s.SetVoice("Vocalizer Expressive Laila Harpo 22kHz") ;Arabic
- return
- Persian:
- s.SetVoice("eSpeak-fa+f2") ;Persian
- return
- Japanese:
- Kyoko:
- s.SetVoice("Vocalizer Expressive Kyoko Harpo 22kHz") ;Japanese
- return
- Haruka:
- s.SetVoice("Haruka, ja-JP MS")
- return
- Chinese:
- Li-li:
- s.SetVoice("Vocalizer Expressive Li-li Harpo 22kHz") ;Chinese
- return
- HuiHui:
- s.SetVoice("HuiHui, zh-CN MS") ;Chinese
- return
- Korean:
- Yuna:
- s.SetVoice("Vocalizer Expressive Yuna Harpo 22kHz") ;Korean
- return
- Heami:
- s.SetVoice("Heami, ko-KR MS") ;Korean
- return
- Hindi:
- s.SetVoice("eSpeak-hi+f2") ;Hindi
- return
- Lekha:
- s.SetVoice("Vocalizer Expressive Lekha Harpo 22kHz") ;Hindi
- return
- s.ToggleSpeak(gst()) ; select some text and press Shift+Alt+F11 to test ToggleSpeak()
- s.NextVoice() ; select some text and press Shift+Alt+F12 to switch to the next voice
- gst() { ; GetSelectedText by Learning one
- IsClipEmpty := (Clipboard = "") ? 1 : 0
- if !IsClipEmpty {
- ClipboardBackup := ClipboardAll
- While !(Clipboard = "") {
- Clipboard =
- Sleep, 10
- }
- }
- Send, ^c
- ClipWait, 0.1
- ToReturn := Clipboard, Clipboard := ClipboardBackup
- if !IsClipEmpty
- ClipWait, 0.5, 1
- Return ToReturn
- }
- ; Class TTS by evilC
- ; Based on code 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, www.autohotkey.com/forum/topic83162.html
- Class TTS {
- VoiceList := [] ; An indexed array of the available voice names
- VoiceAssoc := {} ; An Associative array of voice names, key = voice name, value = voice index (VoiceList lookup)
- VoiceCount := 0 ; The number of voices available
- VoiceNumber := 0 ; The number of the current voice
- VoiceName := "" ; The name of the current voice
- __New(){
- this.oVoice := ComObjCreate("SAPI.SpVoice")
- this._GetVoices()
- this.SetVoice(this.VoiceList.1)
- }
- ; speak or stop speaking
- ToggleSpeak(text){
- Status := this.oVoice.Status.RunningState
- if Status = 1 ; finished
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- Else if Status = 0 ; paused
- {
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- }
- Else if Status = 2 ; reading
- this.oVoice.Speak("",0x1|0x2) ; stop
- }
- ; speak asynchronously
- Speak(text){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- }
- ; speak synchronously
- SpeakWait(text){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x0) ; speak synchronously
- }
- ; Pause toggle
- Pause(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- else if Status = 2 ; reading
- this.oVoice.Pause
- }
- Stop(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- }
- ; rate (reading speed): rate from -10 to 10. 0 is default.
- SetRate(rate){
- this.oVoice.Rate := rate
- }
- ; volume (reading loudness): vol from 0 to 100. 100 is default
- SetVolume(vol){
- this.oVoice.Volume := vol
- }
- ; pitch : From -10 to 10. 0 is default.
- ; http://msdn.microsoft.com/en-us/library/ms717077(v=vs.85).aspx
- SetPitch(pitch){
- this.oVoice.Speak("<pitch absmiddle = '" pitch "'/>",0x20)
- }
- ; Set voice by name
- SetVoice(VoiceName){
- if (!ObjHasKey(this.VoiceAssoc, VoiceName))
- return 0
- While !(this.oVoice.Status.RunningState = 1)
- Sleep, 20
- this.oVoice.Voice := this.oVoice.GetVoices("Name=" VoiceName).Item(0) ; set voice to param1
- this.VoiceName := VoiceName
- this.VoiceNumber := this.VoiceAssoc[VoiceName]
- return 1
- }
- ; Set voice by index
- SetVoiceByIndex(VoiceIndex){
- return this.SetVoice(this.VoiceList[VoiceIndex])
- }
- ; Use the next voice. Loops around at end
- NextVoice(){
- v := this.VoiceNumber + 1
- if (v > this.VoiceCount)
- v := 1
- return this.SetVoiceByIndex(v)
- }
- ; Returns an array of voice names
- GetVoices(){
- return this.VoiceList
- }
- GetStatus(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- Return "paused"
- Else if Status = 1 ; finished
- Return "finished"
- Else if Status = 2 ; reading
- Return "reading"
- }
- GetCount(){
- return this.VoiceCount
- }
- SpeakToFile(param1, param2){
- oldAOS := this.oVoice.AudioOutputStream
- oldAAOFCONS := this.oVoice.AllowAudioOutputFormatChangesOnNextSet
- this.oVoice.AllowAudioOutputFormatChangesOnNextSet := 1
- SpStream := ComObjCreate("SAPI.SpFileStream")
- FileDelete, % param2 ; OutputFilePath
- SpStream.Open(param2, 3)
- this.oVoice.AudioOutputStream := SpStream
- this.SpeakWait(param1)
- SpStream.Close()
- this.oVoice.AudioOutputStream := oldAOS
- this.oVoice.AllowAudioOutputFormatChangesOnNextSet := oldAAOFCONS
- }
- ; ====== Private funcs, not intended to be called by user =======
- _GetVoices(){
- this.VoiceList := []
- this.VoiceAssoc := {}
- this.VoiceCount := this.oVoice.GetVoices.Count
- Loop, % this.VoiceCount
- {
- Name := this.oVoice.GetVoices.Item(A_Index-1).GetAttribute("Name") ; 0 based
- this.VoiceList.push(Name)
- this.VoiceAssoc[Name] := A_Index
- }
- }
- }
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement