DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Silly Idea? A program that counts out loud  (Read 34,394 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Silly Idea? A program that counts out loud
« on: August 10, 2007, 03:10 AM »
I had a funny idea today, and although i can't for the life of me think of a real use for this, it might be a fun project for someone looking to mess around with speech synthesis libraries.

Idea is a small program that just starts counting out loud like:
one, two, three, ..., five thousand and fifty four, ...
and so on until you stop it.

Might be interesting to put it on while you are trying to get to sleep.  I think for something like this it would be nice to use a quality voice library or maybe even custom recordings of the numbers (such a limited vocabulary so it should be possible).

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #1 on: August 10, 2007, 04:44 AM »
Crazy man. :)
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould

AbteriX

  • Member #520
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,150
Re: Silly Idea? A program that counts out loud
« Reply #2 on: August 10, 2007, 07:00 AM »
I see an use for gymnastics.  one, two, three, ...,

Especially if you would include repeating:
REPEAT FROM [ 1] TO [ 20]
and PAUSE before repeating: [ 30]sec.

Then i am able to open an gym, but need to increase
the vocabulary with -- "once again please" -- and -- "the last five now, ladies"
Greetings, Stefan.

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: Silly Idea? A program that counts out loud
« Reply #3 on: August 10, 2007, 10:32 AM »
Should be a fun little programming exercise anyway - once you've made an algorithm that can spell out an integer in English, the rest is pretty simple (until you get into trying to make the stitched-together speech sound natural ;) ).
- carpe noctem

app103

  • That scary taskbar girl
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 5,888
    • Participated in NANY Challenge Six Times
    • Coding Snacks
    • Gathering Badge
    • Cody Award
    • Volunteers/Staff
Re: Silly Idea? A program that counts out loud
« Reply #4 on: August 10, 2007, 11:02 AM »
It would end up sounding like an automated telephone information system at best. (the one for directory assistance)

It doesn't really seem all that hard to do, just thinking about it...but it probably will be harder than I think in practice.

Conquer

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 50
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #5 on: August 20, 2007, 06:38 PM »
Lmfao I actually made it! Still fixing minor bugs

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Silly Idea? A program that counts out loud
« Reply #6 on: August 20, 2007, 09:33 PM »
gimme!  :up:

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #7 on: August 21, 2007, 02:35 AM »
Ever since reviewing ronriel's nifty little r4r media player, I have found a renewed love for AutoIt.

Here is that application in only 5 lines of AutoIt.

Code: (autoit)
$o = ObjCreate("SAPI.SpVoice")
For $i = 1 To 10
	$o.Speak($i)
	Sleep(50)
Next

Oh, I forgot to mention I am running AutoIt 3.2.4.9 and Windows XP SP2.
I code.  Therefore I am.
« Last Edit: August 22, 2007, 03:14 PM by fowmow »

Cpilot

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 293
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #8 on: August 21, 2007, 05:01 AM »
In FBSL
Code: (FBSL)
$apptype console
Dim %t
Dim oSpeak = CreateObject("SAPI.SpVoice")
?"Close console to quit......."
for t = 0 to 15
CallMethod(oSpeak,".Speak %d",t)
next
ReleaseObject(oSpeak)
Pause

Here it is with the dreaded Microsoft agent:
Code: (FBSL)
'$apptype console

dim %oAgent,%oCharacter,%objRequest,%t

oAgent = CreateObject("Agent.Control.2")
PutValue(oAgent,".Connected %b",TRUE)
CallMethod(oAgent,".Characters.Load %s,%s","Merlin","merlin.acs")
oCharacter = GetValue("%o",oAgent,".Characters.Character %s","Merlin")

CallMethod(oCharacter,".Show")
CallMethod(oCharacter,".MoveTo %d,%d",500,300)

CallMethod(oCharacter,".Play %s","Confused")
For t = 0 to 15
CallMethod(oCharacter,".Speak %s",$t)
next
CallMethod(oCharacter,".Hide")
While GetValue("%d",oCharacter,"Visible")
Sleep(250)
Wend
ReleaseObject(oCharacter)
ReleaseObject(oAgent)
« Last Edit: May 23, 2009, 06:28 AM by Cpilot »

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #9 on: August 22, 2007, 03:13 PM »
Following Cpilot's lead, the *dreaded* Microsoft Agent, Merlin.

I mixed it up a bit with the Sleep()'s so it didn't appear as if he paused too long.  And for the record... I believe I could have done this with events, but honestly, I was too lazy to read any more of the Agent SDK.  So it could definitely be done better.

Code: (autoit)
$o = ObjCreate("Agent.Control.2")
$o.Connected = "True"
$o.Characters.Load("Merlin", @WindowsDir & "\msagent\chars\merlin.acs")
$c = $o.Characters.Character("Merlin")
$c.Show()
$c.Play("Confused")
Sleep(3000)
$c.Speak("Count to 10?")
Sleep(6000)
For $i = 1 To 10
	$c.Speak("" & $i & "")
	Sleep(1500)
Next
Sleep(2500)
$c.Think("Well... that was weird.")
Sleep(3000)
$c.Hide()
Sleep(2000)

All of the Sleep()'s are necessary to allow Merlin enough time to speak.  And for those of you who might go, "Hey, I thought these guys were supposed to speak?"

You need a Text-To-Speech engine and SAPI 4.0.

I sat there myself for a time thinking, "Why won't Merlin talk to me?"

*sigh*

Hey Cpilot, they have a code block for FBSL too (in case you didn't already know).
I code.  Therefore I am.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Silly Idea? A program that counts out loud
« Reply #10 on: August 22, 2007, 05:07 PM »
Cool stuff! i'm going to try these and report  :Thmbsup:

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Silly Idea? A program that counts out loud
« Reply #11 on: August 23, 2007, 08:41 PM »
Clever idea CPilot  :up: :up:
Now where is that online fbsl to exe  service that used to be available?

fowmow -- works perfectly  :up: :up:  very fun stuff.

I'm going to try setting this thing to count to 10,000 and see if it helps me go to sleep.

Conquer

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 50
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #12 on: August 23, 2007, 10:49 PM »
Well, heres the version I finished a few days ago
Code
#NoTrayIcon
#SingleInstance, Force
;SetTimer, RealTime, 1000
Active = False
Count = 0
Gui, Add, Button, w100 h25 gStart vStartWp, Start
Gui, Add, Button, w100 h25 yp xp+102 gPause, Pause
Gui, Add, Button, w100 yp xp+102 h25 gStop, Stop
Gui, Add, Text, vCountWp x10 w300 , Current Number: %Count% 
;Gui, Add, Text, vCountSWp x10 w300 , Actual Elapsed Seconds: 0
Gui, +AlwaysOnTop
Gui, Show
return

Stop:
!s::
BreakLoop = True
Count = 0
GuiControl,,CountWp,Current Number: 0 (Stopped)
GuiControl,,StartWp,Start
SoundBeep
Active = False
return

Pause:
!p::
BreakLoop = True
GuiControl,,StartWp,Resume
SoundBeep
Active = False
GuiControl,,CountWp,Current Number: %Count% (Paused)
return

Start:
GuiControl,,StartWp,Start
Active = True
BreakLoop = False
SetTimer, CountTime, 1000
return

CountTime:
If BreakLoop = True
{
    SetTimer, CountTime, Off
    Active = False
}
If Active = False
    return
Count += 1
GuiControl,,CountWp,Current Number: %Count%
;return
;RealTime:
If Active = False
    return
RealCount += 1
;GuiControl,,CountSWp,Actual Elapsed Seconds: %RealCount%
TTS(Count)
return   




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
}

Features:
- Press start to make it start counting. It will keep going forever just as long as the script doesn't close
- The pause key is now fully functional
- There is also a little counter at the bottom that displays the current number.
- And one more thing - hotkeys. Alt+P to pause counting, Alt+S to stop counting

Known Limitations:
- If the script is counting a very large number (ex. one trillion, ten billion, one million, ten thousand, three hundred and fifty four.  ;D ) the script will take a few seconds to pause/stop (it will first finish saying the current number)

« Last Edit: August 23, 2007, 11:46 PM by Conquer »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Silly Idea? A program that counts out loud
« Reply #13 on: August 23, 2007, 11:12 PM »
Nice work conquer  :up:

I wonder if there is a nicer speech engine i could get to make the speaker a bit smoother.

Thanks everyone for the great work on this, this is pretty cool actually.

Conquer

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 50
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #14 on: August 23, 2007, 11:56 PM »
attached in my above post is now a zipped version for anyone who doesn't have an AutoHotkey installation.

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #15 on: August 24, 2007, 01:27 AM »
I wonder if there is a nicer speech engine i could get to make the speaker a bit smoother.

The only things I know of offhand are these (in no particular order):

1.  Use SAPI 5.1, or 5.3 instead of 4.0.  [1, 2, 3]

2.  AT&T Natural Voices

3.  A bunch of other voice libraries.

Thanks everyone for the great work on this, this is pretty cool actually.

And thank you, very much!
I code.  Therefore I am.

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #16 on: August 24, 2007, 01:29 AM »
attached in my above post is now a zipped version for anyone who doesn't have an AutoHotkey installation.

Very cool.  What language was this written in?  Don't forget to use the appropriate codebox.  :)

EDIT:  Duh, I see now "ahk" in the title and you said it was AutoHotKey.  Jeez.  Maybe I should pay better attention!

Now I wonder if GeSHi has any plans to support AutoHotKey?
I code.  Therefore I am.
« Last Edit: August 24, 2007, 03:44 AM by fowmow »

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #17 on: August 24, 2007, 03:53 AM »
Clever idea CPilot  :up: :up:
Now where is that online fbsl to exe  service that used to be available?

http://gedd123.free.fr/studio/
I code.  Therefore I am.

Cpilot

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 293
    • Coding Snacks
Re: Silly Idea? A program that counts out loud
« Reply #18 on: August 24, 2007, 03:59 AM »
Quote from: "fowmow"
Hey Cpilot, they have a code block for FBSL too (in case you didn't already know).
No I didn't fowmow, I'll check it out.
Usually I just open an instance of notepad and throw a script together.

Thanks for the Link to the FBSL ONLINE STUDIO COMPILER, I'd lost it actually.  :Thmbsup:

fowmow

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 46
Re: Silly Idea? A program that counts out loud
« Reply #19 on: August 24, 2007, 06:20 AM »
Quote from: "fowmow"
Hey Cpilot, they have a code block for FBSL too (in case you didn't already know).
No I didn't fowmow, I'll check it out.
Usually I just open an instance of notepad and throw a script together.

Oh!  By "code block" I meant when you put source code here.  Instead of just using:

[ code ][ /code ]

...you can use:

[ code=fbsl ]...[ /code ]

Minus all the spaces of course!

Thanks for the Link to the FBSL ONLINE STUDIO COMPILER, I'd lost it actually.  :Thmbsup:

No problem, Cpilot!
I code.  Therefore I am.

Original address: https://www.donationcoder.com/forum/index.php?topic=9513.0