Jump to content

help with joke script


Recommended Posts

I made a script to mess with a coworker. I was wondering if I could get some help with one small thing, and it would be perfect. I want to get the beeps and the cdtray command to happen at the same time. (Make it look like the PC is having a "moment".) Here is the script..

_talk("Ronald?")
_talk("You hot man!")
_talk("You couldn't wait to touch my keyboard, you naughty boy")
_talk("You know how to make my harddrive spin!")
_talk("Oh!")
_talk("My CD rom drive feels funny.")
_talk("Oh!")
_talk("JUST LIKE THAT!")
_talk("YES")
_talk("YES")
_talk("I think")
_talk("I'm going")
_talk("to")
CDtray("D:", "open")
beep(300, 200)
beep(500, 700)
beep(150, 2000)
CDtray("D:", "close")
beep(300, 200)
beep(500, 700)
beep(250, 800)
beep(600, 200)
CDtray("D:", "open")
beep(500, 700)
beep(600, 200)
CDtray("D:", "close")
_talk("ah")
_talk("that was good")
_talk("do you have a cigarette?")

Func _Talk($sText)
    $tempFile = @TempDir & '\talktemp.vbs'    ; Set the temp file
    FileWriteLine($tempFile, 'Dim Talk' & @CRLF & _
    'Set Talk = WScript.CreateObject("SAPI.SpVoice")' & _
    @CRLF & 'Talk.Speak "' & $sText & '"'); Add contents to the temp file
    RunWait('Wscript.exe talktemp.vbs', @TempDir); Run the VBScript
    FileDelete($tempFile)
EndFunc
Edited by vollyman
Link to comment
Share on other sites

Beep(300,200) will wait 200ms before moving on to the next command. Beep(300,2000) would wait 2000ms before moving on.

You could make the beep durations shorter? in order to make it seem like they are happening at the same time and then just put more of them. I'm not sure I understand what you are asking for exactly.

Link to comment
Share on other sites

Hi,

you could also increase the understandability of the speech with this speak func.

#include <inet.au3>
Dim $voice = ObjCreate("Sapi.SpVoice")
Speak(@IPAddress1 , 0.75 , 100)
MsgBox(0, "IP-Addresse", "Deine IP-Adresse lautet: " & @IPAddress1)
Func Speak($Text, $Rate, $Vol)
    $voice.Rate = $Rate
    $voice.Volume = $Vol
    $voice.Speak($Text)
EndFunc  ;==>Speak

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

You could also add this line into first line in Megas Function to make the voice Female.

$voice.voice = $voice.GetVoices("Name=LH Michelle").Item(0)

The Name= might be different on your pc. Microsoft Mary is in a lot of the online examples but I only had LH Michelle for female voices.

Mike

Link to comment
Share on other sites

Hi,

you could also increase the understandability of the speech with this speak func.

#include <inet.au3>
Dim $voice = ObjCreate("Sapi.SpVoice")
Speak(@IPAddress1 , 0.75 , 100)
MsgBox(0, "IP-Addresse", "Deine IP-Adresse lautet: " & @IPAddress1)
Func Speak($Text, $Rate, $Vol)
    $voice.Rate = $Rate
    $voice.Volume = $Vol
    $voice.Speak($Text)
EndFunc ;==>Speak

So long,

Mega

Ooooh... that's interesting... :D

I read up on SAPI at the Microsoft Scriptguy site, and tried this:

_Speak("This is my speach test.", 0.9, 90, "Microsoft Mary")

; ---------------------------
;   Function _Speak()
;       Voice text reader using native SAPI
;   Call with _Speak($sText, $iRate, $iVol, $sVoice) where:
;       $sText = The text to read
;       $iRate = (optional) the rate at which to read, 1=full speed (default), 0.5=slower
;       $iVol = Volume percentage from 0 to 100 (default = 100, full)
;       $sVoice = Name of the voice to use, by default only "Microsoft Sam" is loaded,
;           optional voices like "Microsoft Mary" or "Microsoft Mike" may be present
;   On success returns 1
;   On fail returns 0 and:
;       @Error = 1, parameter error
;      @Error = 2, object creation error
;       @Error = 3, speaking error
; ---------------------------
Func _Speak($sText, $iRate = 1, $iVol = 100, $sVoice = "Microsoft SAM")
    If IsString($sText) And IsNumber($iRate) And $iVol <= 100 And IsString($sVoice) Then
        Local $objSpeach = ObjCreate ("Sapi.SpVoice")
        If @error = 0 Then
            $objSpeach.GetVoices ("Name=" & $sVoice)
            $objSpeach.Rate = $iRate
            $objSpeach.Volume = $iVol
            $objSpeach.Speak ($sText)
            If @error = 0 Then
                Return 1
            Else
                Return SetError(3, 0, 0)
            EndIf
        Else
            Return SetError(2, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc  ;==>_Speak

But the selection of other voices doesn't work. Whichever voice is selected as default in the Speech control panel applet is used. Is my $objSpeach.GetVoices ("Name=" & $sVoice) call wrong?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

But the selection of other voices doesn't work. Whichever voice is selected as default in the Speech control panel applet is used. Is my $objSpeach.GetVoices ("Name=" & $sVoice) call wrong?

:D

If you have windows XP go into Control panel, Speech, Text to Speech Tab. the Voice Selection Combo box is all the voices you have loaded. you should be able type into your ("Name=Voice From Combo")

Mike.

Link to comment
Share on other sites

If you have windows XP go into Control panel, Speech, Text to Speech Tab. the Voice Selection Combo box is all the voices you have loaded. you should be able type into your ("Name=Voice From Combo")

Mike.

Huh? :D

I'm on XP Pro SP2 with the SAPI5 SDK loaded. The control panel applet lists Microsoft Mary, Mike, and Sam. The issue is that the script function can't select them on the fly. Is it not possible with the object I used?

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Huh? :D

I'm on XP Pro SP2 with the SAPI5 SDK loaded. The control panel applet lists Microsoft Mary, Mike, and Sam. The issue is that the script function can't select them on the fly. Is it not possible with the object I used?

This worked fine for me. it switches the voice to LH Michelle, which you may not have. you may need Microsoft Mary or whatever is listed in your Voice ComboBox.

$voice = ObjCreate("Sapi.SpVoice")
$voice.voice = $voice.GetVoices("Name=LH Michelle").Item(0)
$voice.Rate = 1
$voice.Volume = 50
$voice.Speak("Hello, How are you doing?")
Link to comment
Share on other sites

This worked fine for me. it switches the voice to LH Michelle, which you may not have. you may need Microsoft Mary or whatever is listed in your Voice ComboBox.

$voice = ObjCreate("Sapi.SpVoice")
$voice.voice = $voice.GetVoices("Name=LH Michelle").Item(0)
$voice.Rate = 1
$voice.Volume = 50
$voice.Speak("Hello, How are you doing?")
Ahhh, so! :D

I did screw it up! This is fixed as per your post, and the definition of rate is fixed per MSDN:

_Speak("My name is Microsoft Mary. Rate is negative ten.", -10, 100, "Microsoft Mary")
Sleep(1000)
_Speak("My name is Microsoft Mike. Rate is zero.", 0, 100, "Microsoft Mike")
Sleep(1000)
_Speak("My name is Microsoft Sam. Rate is ten.", 10, 100, "Microsoft Sam")
Sleep(1000)
_Speak("My name is Microsoft Mary. Volume is thirty three.", 0, 33, "Microsoft Mary")
Sleep(1000)
_Speak("My name is Microsoft Mike. Volume is sixty six.", 0, 66, "Microsoft Mike")
Sleep(1000)
_Speak("My name is Microsoft Sam. Volume is one hundred.", 0, 100, "Microsoft Sam")

; ---------------------------
;   Function _Speak()
;       Voice text reader using native SAPI
;   Call with _Speak($sText, $iRate, $iVol, $sVoice) where:
;       $sText = The text to read
;       $iRate = (optional) the rate at which to read, 10=fastest, 0=normal (default), -10=slowest
;       $iVol = Volume from 0 to 100 (default = 100, full)
;       $sVoice = Name of the voice to use, by default only "Microsoft Sam" is loaded,
;           optional voices like "Microsoft Mary" or "Microsoft Mike" may be present
;   On success returns 1
;   On fail returns 0 and:
;       @Error = 1, parameter error
;      @Error = 2, object creation error
;       @Error = 3, speaking error
; ---------------------------
Func _Speak($sText, $iRate = 1, $iVol = 100, $sVoice = "Microsoft SAM")
    If IsString($sText) And IsNumber($iRate) And $iVol <= 100 And IsString($sVoice) Then
        Local $objSpeech = ObjCreate ("Sapi.SpVoice")
        If @error = 0 Then
            $ObjSpeech.Voice = $objSpeech.GetVoices ("Name=" & $sVoice).Item (0)
            $objSpeech.Rate = $iRate
            $objSpeech.Volume = $iVol
            $objSpeech.Speak ($sText)
            If @error = 0 Then
                Return 1
            Else
                Return SetError(3, 0, 0)
            EndIf
        Else
            Return SetError(2, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc  ;==>_Speak

Thanks! :D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...