Asked — Edited
Resolved Resolved by Rich!

Two Scripting Questions

I'm just not finding what I'm looking for so I have two questions I need to ask:

1.) I want to be able to pause speech recognition for the duration of a sound file being played and I don't want to specify the amount of time. For example if I play a sound file and want to pause the speech recognition for 9 seconds I know I can do it like so:


ControlCommand( "Speech Recognition", PauseMS, 9000)

What I want is something more like:


#this plays a song from my Music sound board
ControlCommand("Music", Track_0)
ControlCommand( "Speech Recognition", Pause, until end of Track_0)

Is that possible?

2.) When you play a random track, is there a method to grain the value of the random track? For example this will play a random track from my sound board:


ControlCommand("Answer to Bender", Track_Random)

I've noticed the Track_Random often selects the same track. What I want to be able to do is discover the number of the random track - use the value to set a variable - then use that variable to ensure a different track is select the next time the script is ran. It doesn't look like there is a way to grain the number of the Track_Random (or at least it might not be documented)?

Thank you all in advance for your advice and suggestions!


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

United Kingdom
#1  

Please bear in mind it is far past my bedtime and I am running on empty...

  1. As far as I know there is no command which will wait until a sound file is finished. It may be possible to use the Sound servo (EZB) control and use the variable which it stores the sound level as, so something like;

ControlCommand("Music", Track_0)
ControlCommand("Speech Recognition", PauseOn)
RepeatUntil($Soundv4Value = 0)
#Waiting for music to stop - just do nothing here...
EndRepeatUntil
ControlCommand("Speech Recognition", PauseOff)

  1. Set up a random number generator and use that in the ControlCommand?

$tracknumber = GetRandom(0,100)
ControlComman("Answer To Bender", Track_+$tracknumber)

Add some ifs and save the picked tracks as variables so they aren't repeated?


$tracknumber = GetRandom(0,100)
:loop
IF($tracknumber = $tracknumber1 or $tracknumber = $tracknumber2 or $tracknumber = $tracknumber3)
  $tracknumber = GetRandom(0,100)
EndIf
Goto(loop)

# Save last few tracks played
$tracknumber3 = $tracknumber2
$tracknumber2 = $tracknumber1
$tracknumber1 = $tracknumber

#2  

RepeatUntil($Soundv4Value = 0)

Error for that line, not defined. This is with a version 3 EZb, not a v4.

#3  

It does not appear that the ControlCommand will respect variables as part of the command. As I get "Unknown window control command" for line 2 in even this code to just see if a variable can be used in the controlCommandParameter.


$track = "Track_0"
ControlCommand("Bender Songs", $track)

I should have added I tried that with a variable already. I too thought GetRandom might be a good solution.

It might be that what I'm asking for is not possible at this time, which is ok.

#4  

Justin, you are over my head. But , why wouldn't the sayWait command do the job?

#5  

@Rich, your script gave me an idea for the random tracks, since the controlCommandParameter would not take a variable I took what you had and did this:


$tracknumber = GetRandom(0,8)
IF($tracknumber = $tracknumber1 or $tracknumber = $tracknumber2 or $tracknumber = $tracknumber3)
$tracknumber = GetRandom(0,8)
EndIf
IF ($tracknumber = 0)
ControlCommand("Bender Songs", Track_0)
ElseIf ($tracknumber = 1)
ControlCommand("Bender Songs", Track_1)
ElseIf ($tracknumber = 2)
ControlCommand("Bender Songs", Track_2)
ElseIf ($tracknumber = 3)
ControlCommand("Bender Songs", Track_3)
ElseIf ($tracknumber = 4)
ControlCommand("Bender Songs", Track_4)
ElseIf ($tracknumber = 5)
ControlCommand("Bender Songs", Track_5)
ElseIf ($tracknumber = 6)
ControlCommand("Bender Songs", Track_6)
ElseIf ($tracknumber = 7)
ControlCommand("Bender Songs", Track_7)
ElseIf ($tracknumber = 8)
ControlCommand("Bender Songs", Track_8)
EndIf


# Save last few tracks played
$tracknumber3 = $tracknumber2
$tracknumber2 = $tracknumber1
$tracknumber1 = $tracknumber

I have 8 tracks (haha 8-track) (ok, technically 9 tracks) and this works MUCH better than Track_Random :D

#6  

@MovieMaker - good thought on sayWait. That would work well for text to speech output where the PC is generating the voice. What I'm doing is playing a sound file from a "Sound Board" and I'm looking for a way to achieve the a similar functionality for playing sounds or music files. It doesn't look like sayWait works for sound boards.

United Kingdom
#8  

@Justin that would have been my second option. I don't know if ControlCommand does accept variables or not to be honest (I have never tried) but an IF nest with different ControlCommands as you have written should work without problem.

With the V3, use the V3 sound servo control and the V3 sound servo variable. You may need to adjust it from 0 if there is background noise etc. but the principle should work.

#9  

@Rich, it's really close to working. Here is my code to pause the speech recognition during sound file play back from a sound board and using the Sound Servo(pc):


ControlCommand("Music", Track_0)
sleep(1000)
ControlCommand("Speech Recognition", PauseOn)
sleep(1000)
RepeatUntil($SoundPlayValue = 0)
#Waiting for music to stop - just do nothing here...
EndRepeatUntil
ControlCommand("Speech Recognition", PauseOff)

The sleep statements are in there to give the music a couple of seconds to start. It does set the state of speech recognition to paused, but only for a couple of seconds because the sound the Sound servo takes in is audio from the PC mic so the sound from my PC speakers have to be loud enough to keep the value above a value of 0 and the sound level even turned up would not keep the value from falling down to 0.

I did increase update speed to 4000(ms) and moved the mic right next to a speaker - do this the above script did exactly what I wanted, an automated pause of speech recognition during sound file playback.

For testing / proof of concept this worked. For practical use I don't think it will perform as I was hoping. If the sound source could be selected, between mic and the PC's own sound output we'd be in business! :)

#10  

And that solution, even if the Sound servo (PC) had the option to intake only the PC's own output it would not work for sound files with any pauses or moments with no sound in it.

Just thinking out loud, it probably needs a solution built in .NET because playing the sound file is an underlining .NET windows function and .NET must have a method to know when a sound files ends, other wise windows media player would not know when to play another track or file.

I just found an example of the how use .NET to detect when the end of a file is played.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562692(v=vs.85).aspx

That's just a shout out to the EZ-Robot crew incase they feel that might be a handy feature to add in the future.

United Kingdom
#11  

So basically, the repeatuntil needs to be until the sound level is 0 for x number of seconds ideally. I'll have to think about how to do that (I'm sure it's possible somehow).

Possibly something to do with the RepeatWhile may work... I'll do some playing later and see what I can figure out.

#12  

<sound level is 0 for x number of seconds> Ahhh.....hum....yes...Hummmmmmmm lol I'll have to think on that too!

United Kingdom
#13  

I keep coming up blank on the $soundlevel = 0 for x seconds code. I have a few ideas but so far they have all had their own little problems... possibly because my eyelids are very heavy. I'll give a couple of other ideas a shot tomorrow though.

I'm sure something can be figured out using the RepeatWhile() command along with the $seconds variable or a simple counter variable and some $x = $x+1 with sleeps.

I'll have another look at it once I've had some much required sleep if you don't come up with anything in the mean time.

#14  

I'm going to mark this as solved, because we more or less determined what can and can't yet be done in the scripting.

Thank you Rich for your ideas and work around. I think I'm going to try to make a 3rd party app that monitors the actually speaker output from the PC and uses that to send a variable to ARC. I need to develop this function for some other ideas I have as well.

United Kingdom
#15  

I'll work on a script of some kind soon I've just been very busy recently with work, sorting out my house and a few other things so I've had to put EZ-Robot stuff to the side temporarily. I'm confident something can be done to monitor the sound through the sound servo control's variable and some kind of timing script or counter which monitors and detects a longer dip in volume (therefore indicating sound has finished).

Failing that, the sleep() command along with accurate timing could always work. It may mean adding more and more scripts and triggering sounds via ControlCommand to run the script that plays the sound followed by a sleep of the same length as the sound... The "ScriptStartWait" function of ControlCommand would be ideal as this pauses the script calling the ControlCommand until the script started has finished (see my Ping Roam 2.0 for examples of ScriptStartWait)