AutoHotkey Community

It is currently May 24th, 2012, 5:58 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 46 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: February 11th, 2007, 7:17 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Well its yet another tts script but this one doesn't create a tempfile. It uses the Speech API directly.

Here you can download the TTS.ahk includefile and an example file.

Or you can copy the example in the codebox below.
Code:
TTS(sSpeechText, dwFlags=0)
{
    ;For info on the dwFlags bitmask see the SAPI helpfile:
    ;http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/sapi.chm

    static TTSInitialized, ppSpVoice, pSpeak

    wSpeechTextBufLen:=VarSetCapacity(wSpeechText, StrLen(sSpeechText)*2+2,0)
    DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "Str", sSpeechText, "Int", -1, "UInt", &wSpeechText, "Int", wSpeechTextBufLen/2)

    if !TTSInitialized
    {
        ComInit := DllCall("ole32\CoInitialize", "Uint", 0)
        if ComInit not in 0,1
            return "CoInitialize() failed: " ComInit

        sCLSID_SpVoice:="{96749377-3391-11D2-9EE3-00C04F797396}"
        sIID_ISpeechVoice:="{269316D8-57BD-11D2-9EEE-00C04F797396}"
        ;Make space for unicode representations.
       wCLSID_SpVoiceBufLen:=VarSetCapacity(wCLSID_SpVoice, StrLen(sCLSID_SpVoice)*2+2)
       wIID_ISpeechVoiceBufLen:=VarSetCapacity(wIID_ISpeechVoice, StrLen(sIID_ISpeechVoice)*2+2)
       ;Convert to unicode
       DllCall("MultiByteToWideChar", "UInt",0, "UInt",0, "Str",sCLSID_SpVoice, "Int",-1, "UInt",&wCLSID_SpVoice, "Int",wCLSID_SpVoiceBufLen/2)
       DllCall("MultiByteToWideChar", "UInt",0, "UInt",0, "Str",sIID_ISpeechVoice, "Int",-1, "UInt",&wIID_ISpeechVoice, "Int",wIID_ISpeechVoiceBufLen/2)
       
        ;Convert string representations to originals.
        VarSetCapacity(CLSID_SpVoice, 16)
        VarSetCapacity(IID_ISpeechVoice, 16)
        if ret:=DllCall("ole32\CLSIDFromString", "str", wCLSID_SpVoice, "str", CLSID_SpVoice)
        {
            DllCall("ole32\CoUninitialize")
            return "CLSIDFromString() failed: " ret
        }
        if ret:=DllCall("ole32\IIDFromString", "str", wIID_ISpeechVoice, "str", IID_ISpeechVoice)
        {
            DllCall("ole32\CoUninitialize")
            return "IIDFromString() failed: " ret
        }
   
        ;Obtain ISpeechVoice Interface.
        if ret:=DllCall("ole32\CoCreateInstance", "Uint", &CLSID_SpVoice, "Uint", 0, "Uint", 1, "Uint", &IID_ISpeechVoice, "UintP", ppSpVoice)
        {
            DllCall("ole32\CoUninitialize")
            return "CoCreateInstance() failed: " ret
        }
        ;Get pointer to interface.
        DllCall("ntdll\RtlMoveMemory", "UintP", pSpVoice, "Uint", ppSpVoice, "Uint", 4)
        ;Get pointer to Speak().
        DllCall("ntdll\RtlMoveMemory", "UintP", pSpeak, "Uint", pSpVoice + 4*28, "Uint", 4)

       
        if ret:=DllCall(pSpeak, "Uint", ppSpVoice, "str" , wSpeechText, "Uint", dwFlags, "Uint", 0)
        {
            DllCall("ole32\CoUninitialize")
            return "ISpeechVoice::Speak() failed: " ret
        }

        DllCall("ole32\CoUninitialize")

        TTSInitialized = 1
        return
    }

    if ret:=DllCall(pSpeak, "Uint", ppSpVoice, "str" , wSpeechText, "Uint", dwFlags, "Uint", 0)
        return "ISpeechVoice::Speak() failed: " ret
}


;Some usage examples. #####################################
TTS("You can read simple text.")

xmltext=
(
<xml version="1.0">
    <SAPI>
        If the first character of the text is a less then character and the dwFlags parameter is 0 the text will be parsed as xml.
        With the use of xml markup
        <VOICE REQUIRED="NAME=Microsoft Sam">you can</VOICE>
        <VOICE REQUIRED="NAME=Microsoft mike">choose</VOICE>
        <VOICE REQUIRED="NAME=Microsoft Mary">which voice</VOICE>
        <VOICE REQUIRED="NAME=Microsoft Sam">you wish to hear. And much more.</VOICE>
    </SAPI>
</xml>
)
TTS(xmltext)


FileAppend ,
(
You can also specify a fully qualified path to a file and set the dwFlags param to 4. This way the files text will be read.
), tmpspeech.txt
TTS(A_ScriptDir "\tmpspeech.txt", 0 | 4)
FileDelete, tmpspeech.txt


TTS("There are even more features. For details read the speech API documentation.")


Last edited by foom on February 13th, 2007, 1:27 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2007, 11:41 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
It reports

---------------------------
CLSIDFromString() failed: -2147221005
---------------------------


here...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2007, 7:40 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Ooops. Thanks for the report. Should be fixed now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 9:25 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Still doesn't work here.
Strangely enoguh, return is empty string and manualy traversing to code showed me that all dllcalls executed with correct return codes. Still, script exits the same moment as it enters...

Speak is of coursed installed. I use it with Babylon Pro.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 10:42 am 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Strange. Which version do you have installed? I have 5.1 SDK on my machine and 5.1 Redist on the machine of my brother and it works on both.


Last edited by foom on February 13th, 2007, 1:13 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 11:10 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
foom wrote:
I please people that read this to try it out and give feedback if it works for them even if they are not interested in tts.

It worked fine here.
BTW, the error message -2147221005 is "invalid class string", so looks like something got wrong during copy and paste.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 11:13 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
it works, I was using wrong version. Sorry.

I created COM page here for colaborative work:

http://www.autohotkey.com/wiki/index.ph ... M_Wrappers

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 12:11 pm 
Offline

Joined: September 2nd, 2006, 6:39 am
Posts: 279
Location: Scotland
It worked for me using your example


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 13th, 2007, 12:33 pm 
Hello,

just tried it this way:
Code:
#s::
TTS("You can read simple text.")
return

TTS(sSpeechText, dwFlags=0)
{
;For info on the dwFlags bitmask see the SAPI helpfile:
......here follows your script...

it simply does not speak at all, although it is executed. I habve SAPI 4 and SAPI5 installed with a bunch of voices.

Did I call the function wrong?

Cheers,
Keffi


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 1:10 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Thanks for the feedback.
@ Sean
Yeah i know what the code means. I deleted a comma while bringing the dllcalls down to one line and that cause the error.

@ keffi
Which ahk version do u use? I requirres 1.0.46.08.
I edited my first post so u need to copy and paste only once and run it.

@ majkinetor
Thanks for mentioning the wikipage. The artikle on codeprojekt is very educational. A very good read for COM newbies like me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 1:41 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I added you script to the wiki.

I did this as an example of wiki usage and authors should add their script to relevant places so we can keep things organised.

Thx goes to jonny who polished ahk wiki.


http://www.autohotkey.com/wiki/index.ph ... rs#Scripts


I also created global autohotkey.net account to keep there files for download.

Account name and pass: anonymous
Put the COM realted scripts in COM\Scripts directory.

_________________
Image


Last edited by majkinetor on February 13th, 2007, 1:51 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 13th, 2007, 1:46 pm 
Offline

Joined: February 13th, 2007, 1:14 pm
Posts: 2
Location: Germany
Well, I used sub-version .06 and guess what, after upgrading to .08 it works perfectly. Thanks a lot for this fine done script and your excellent support. As a blind user I'm always intersted in putting speech output to my scripts in the most efficient way. This will bring me a step forward.

Cheers, Keffi

_________________
Blindness is the opportunity to see more


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 2:06 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Thanks for adding the script. Althought i am doubtfull about creating libraries because of ahks lack of elementary features to support librarys. However, its nice to see that someone takes the initiative. Hopefully Chris will recognise and honor this and start working on features that aid libraries.
majkinetor wrote:
I also created global autohotkey.net account to keep there files for download.

I have the feeling that this is a bad idea. This might sooner or later get abused eighter to change scripts to do harmfull things or to upload illegal content. You might want to inforn Titan as he is in charge for the site.


Last edited by foom on February 13th, 2007, 2:26 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 2:21 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I don't think so.

ppl can change entire ahk wiki to contain malitious scripts now, yet, they don't do it. Or they do, we will never know. That is the wiki my friend. You will have to beleive or not use it at all.

Well, I beleive, thats why I use it.


Quote:
You might want to inforn Titan as he is in charge for the site.
This is regular ahk.net usage, nothing is invalid in it. The fact that it is open changes nothing. Feel free foom to update the download links in the wiki to your user space anytime so, you can be sure noone will ever change it.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 2:29 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Ok the malicious code issue is nonsense on second thought. But still. If someone uses it for illegal activities, Titan is in charge and he should be informed.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn, tic and 15 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