none
Talk Clock: Strange problems with Sound.Play & Sound.PlayAndWait RRS feed

  • General discussion

  • Hello,

    We tried writing a simple 'Talking Clock' program for my son's science project.  The purpose of this program is to display large digital clock on the screen, which speaks the current time out loud whenever a key is pressed.  His premise being that it is a tool to teach kids time, or a useful program for the blind :) 

    He had recorded spoken numbers 0-19, 20, 30, 40, 50 and the words AM and PM using his own voice, and we saved them as 0.wma, 1.wma, 2.wma... and so on, into a folder C:\Program Files\TalkClock\.  Then we've concocted the program below (WMAs not attached)

    While it seems OK to me, it does not work quite right. It works the very first time (first key press), but it won't play (speak) again *if* the WMAs to be played are the same as already played before. It just skips them. Do we need to clear the Sound somehow? Known issue or something wrong with our code?

    Much appreciated! :)

    ----------------------

    GraphicsWindow.Width = 720
    GraphicsWindow.Height = 540
    GraphicsWindow.FontSize = 80

    GraphicsWindow.KeyUp = SayTime      ''key press event to call speech subroutine

    Loop:                               ''main loop (draws clock)      
      GraphicsWindow.Clear()
      hour = Clock.Hour
      minute = Clock.Minute
      second = Clock.Second
      GraphicsWindow.DrawText(120,200,hour + " : " + minute + " : " + second)
      Program.Delay(1000)
    Goto Loop


    Sub SayTime                   '' speech subroutine
     
      If hour > 12 Then           '' convert current hour to 12-hour format (for speech)
        sayhour = hour - 12        
      Else
        sayhour = hour
      EndIf
     
      If minute > 49 Then         '' break up minutes over 19 into two speech parts e.g. 52 into 50 and 2
        saymin1 = 50
        saymin2 = minute - 50
      ElseIf minute > 39 Then
        saymin1 = 40
        saymin2 = minute - 40
      ElseIf minute > 29 Then
        saymin1 = 30
        saymin2 = minute - 30
      ElseIf minute > 19 Then
        saymin1 = 20
        saymin2 = minute - 20
      Else
        saymin2 = minute
      EndIf
     
      '' say the HOUR
      Sound.PlayAndWait("C:\Program Files\TalkClock\" + sayhour + ".wma")
     
      ''say the MINUTES
      If minute > 20 Then         '' when 20 min or more, say 20, 30, 40, or 50                  
        Sound.PlayAndWait("C:\Program Files\TalkClock\" + saymin1 + ".wma")
      ElseIf minute < 10 Then     '' when less than 10 min, precede with spoken 'O'
        Sound.PlayAndWait("C:\Program Files\TalkClock\0.wma")
      EndIf
       
      If saymin2 > 0 Then         '' say 1 - 19
        Sound.PlayAndWait("C:\Program Files\TalkClock\" + saymin2 + ".wma")
      EndIf
     
      '' say AM or PM
      If hour > 12 Then
        Sound.Play("C:\Program Files\TalkClock\pm.wma")
      Else
        Sound.Play("C:\Program Files\TalkClock\am.wma")
      EndIf
     
    EndSub
    Sunday, February 15, 2009 5:01 PM

All replies

  • The Sound.Play operations are designed to be like a Media player where you can play a track, pause it and stop it on demand.  What's happening here is that the track pointer starts from the beginning, plays through the track and puts the pointer at the end of the track.  Hence when you try playing it for the second time, it doesn't have anything to play. 

    What you'd have to do in your case is to first "stop" the track and restart it.  For example,

      Sound.PlayAndWait("C:\Program Files\TalkClock\" + sayhour + ".wma")
      Sound.Stop("C:\Program Files\TalkClock\" + sayhour + ".wma")

    And then you can play it multiple times. 
    Sunday, February 15, 2009 7:33 PM
    Moderator
  • OK, I added the Stop commands following all instances where we played a sound -- that did it!  But... just an opinion, if a sound does play back in entirety (such as when allowing Sound.PlayAndWait to finish), wouldn't it be simpler and more intuitive to reset the pointer back to the beginning?  In any event, thanks Vijaye!
    Monday, February 16, 2009 6:37 PM
  • You're right, PeterDad.  I've actually taken note of this issue and I'll fix it for the next release.  It *is* kinda lame to require the user to call Stop when the sound has clearly stopped playing.
    Monday, February 16, 2009 10:37 PM
    Moderator
  • Thanks for this post, I am a begginer and just recently began working on the curriculum 2.4 sound, program and text objects and my programs didn't seem to work as they should, I will try adding stop to see if i can get them to do what I want Thanks again
    • Edited by Vdian Monday, August 20, 2012 1:23 PM
    Monday, August 20, 2012 1:23 PM
  • Hi again!

    It would be better if you opened a new thread and publish the code you're having trouble with.

    Besides, this thread here is more than 3 years old  {Monday, February 16, 2009 10:37 PM} !  @_@


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Monday, August 20, 2012 4:37 PM
    Answerer