Sign in to follow this  
Followers 0
Vivvic

GUI not setting variable?

5 posts in this topic

Not sure why GUI wont change the variable

#include <GuiConstants.au3>

GuiCreate("Text to mp3", 392, 321,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$IB = GuiCtrlCreateEdit("Input text here", 20, 10, 350, 260)
$Done = GuiCtrlCreateButton("Done", 100, 280, 160, 30)
$text = GUICtrlRead($ib)
;$text = "1 freedom of speech:2 bear arms:3 quartering of troops:4 search and siesure:5 plea the fifth/double jepordy:6 trial:7 trial by jury:8 cruel punishment:9 right for people:10 state rights:11 suits aginst states:12 president/vice president:13 slavery:14 equal treatment:15 all men vote:16 direct tax:17 direct election:18 prohibition:19 women vote:20 lame duck:21 end prohibation:22 terms of president:23 D.C. electors:24 poll tax:25 president disability:26 voteing age from 21 to 18:27 congresses pay"
$mp3file = @scriptdir&"\amendments.mp3"

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Done
        _text2mp3($text,$mp3file,"Microsoft Mike")
        SoundPlay ($mp3file,true)
    EndSelect
WEnd
Exit


;
func _text2mp3($text,$mp3file,$myvoice="",$lameoptions="")
    $lameexe = @scriptdir&"\lame.exe"
   
    $tempwav = @tempdir & "\" & random(1000,9999) & ".wav"

    $SSFMCreateForWrite = 3
    $objVOICE = ObjCreate("SAPI.SpVoice")
    $objFSTRM = ObjCreate("SAPI.SpFileStream")
    $objVTOKN = ObjCreate("SAPI.ISpeechObjectToken")

    if $myvoice <> "" Then
        dim $aVoices[1]
        $vIndex = -1
        $sVoices = ""
        For $objVTOKN In $objVOICE.GetVoices()
            $vIndex += 1
            redim $aVoices[$vIndex+1]
            $aVoices[$vIndex] = $objVTOKN.GetDescription()
            $sVoices &= @crlf & "  " & $objVTOKN.GetDescription()
        Next
        $noVoice = True
        for $i = 0 to Ubound($aVoices)-1
            if stringinstr($aVoices[$i],$myvoice) Then
                $objVOICE.Voice = $objVOICE.GetVoices().Item($i)
                $noVoice = False
                ExitLoop
            EndIf
        Next
   
        if $novoice Then
            $errmsg = "The following voices are installed on your system:"&@crlf &$sVoices
            $errmsg &= @crlf & @crlf & "Continuing with the default SAPI voice."
            msgbox(16,'Cannot find voice "'&$myvoice&'"',$errmsg)
        EndIf
    EndIf

    consolewrite("Speaking to WAV file..."&@crlf)
    $objFSTRM.Open($tempwav , $SSFMCreateForWrite, False)
    $objVOICE.AudioOutputStream = $objFSTRM
    $objVOICE.Speak($text)
    $objFSTRM.Close
    $objFSTRM = 0
    $objVOICE = 0

    consolewrite("Encoding WAV file to MP3..."&@crlf)
    $return = runwait('"'&$lameexe&'" '&$lameoptions&' "'&$tempwav&'" "'&$mp3file&'"',@scriptdir, @SW_HIDE)
    consolewrite("Lame.exe exit code: "&$return & @crlf)
    filedelete($tempwav)   
    return $return
EndFunc

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)


[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Share this post


Link to post
Share on other sites

That's because you set $IB to the text "Input text here" and then read straight from that with GUICtrlRead().

Instead of setting $text at the beginning, put $text in the loop.

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Done
        $text = GUICtrlRead($IB)
        _text2mp3($text,$mp3file,"Microsoft Mike")
        SoundPlay ($mp3file,true)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

Thank you ^^ I'm sure I will use this info in the future as well.


[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0