Page 1 of 1

sounds

Posted: Mon Jan 10, 2011 12:52 am
by zuel
I can't seem to find any documentation, how does one play sounds in MicroMacro?

I've seen one post "\a" indicating to play the system beep. But nothing on a wav file or a generated tone.

Re: sounds

Posted: Mon Jan 10, 2011 1:59 am
by Administrator
Yeah, unfortunately, printing the \a (alarm) character is the (currently) only sound available. I intend to allow for a full sound system eventually. If I get some time tomorrow (as I might hopefully only have a half day, assuming that these 2 other clients of mine don't need anything done), I might be able to quickly implement some code to allow for more control over the internal speaker (pretty much just like \a, except it allows you to set the frequency and duration...pretty much similar to a MIDI, but for the internal speaker). I'll look into finding a library for playing audio files, but I have very specific requirements (most importantly, it must be very light-weight).

Re: sounds

Posted: Mon Jan 10, 2011 12:45 pm
by zuel
Thanks for the very fast reply.

I see a few projects on the internet for sound integration into Lua. I don't think sound was ever an intention for LUA I guess. My lack of fully understanding of LUA and how MicroMacro, or even any language, Integrates the LUA engine shows my newbness here. But could I integrate one of these projects myself without any changes to MicroMacro?

BTW- I think MicroMacro is absolutely fantastic. I've been a big fan of AutoIt, but let me tell you, MicroMacro really ups the level on AutoIt. I am also really beginning to dig the LUA language.

Re: sounds

Posted: Mon Jan 10, 2011 5:00 pm
by Administrator
Well, I've got good news. I now have some code in-place that will load and play WAV audio files using OpenAL.

Here's an example:

Code: Select all

function main()
	local s = soundLoad("stereo.wav");

	soundPlay(s);
	rest(200);
	soundPause(s);
	rest(200);
	soundPlay(s);
	rest(5000);
end
startMacro(main, true);
Once I've finished this, I'll upload the updated MicroMacro package. Can you think of anything else that will be needed (other than different formats)?

Re: sounds

Posted: Mon Jan 10, 2011 6:11 pm
by zuel
I am not sure what others may find uses for playing sounds. I know my purpose is for an alarm. My specific case is a captcha is displayed while the bot is playing, I need a sound to indicate the bot needs manual intervention.

The only thing I can think of is adjusting the volume.

Great Job!


Thanks!

Re: sounds

Posted: Mon Jan 10, 2011 6:39 pm
by Administrator
Ok, I've added per-sound volume control, looping, state-checking, and error logging. That should be just about all that's needed for most purposes.

Functions are:
  • soundLoad(filename) - Loads a sound. Make sure you include the proper path (make use of getExecutionPath() if the sound file exists inside the script's folder). Returns a sound resource.

    soundPlay(soundresource) - Plays a sound.

    soundStop(soundresource) - Stops a sound.

    soundPause(soundresource) - Pauses a sound.

    soundGetState(soundresource) - Returns the state of a sound as a string ("playing", "paused", "stopped", "initial").

    soundSetVolume(soundresource, volume) - Sets the volume for a sound. Volume should between 0 (no sound) and 1.0 (100%). The volume can exceed 1.0 if your sound card supports it (this would effectively make the sound louder, obviously).

    soundSetLooping(soundresource, loop) - Sets whether to loop a sound or not. 'loop' should be true or false. You should set this before playing the sound (if you need to change it).

Re: sounds

Posted: Mon Jan 10, 2011 11:56 pm
by zuel
Perfect. Took me a few tries. I guess I don't know when the last time I had to worry about escape sequences in strings. I should have realized faster we are dealing with c strings. LOL. Once I dbl escaped the backslash, it all worked.

:)

Great Job!

Re: sounds

Posted: Sun Sep 11, 2011 10:58 pm
by Ajoir
This its my code:

Code: Select all

local soundresource = soundLoad(getExecutionPath() .. "/alarm.wav");
....
soundPlay(soundresource);
And this is the answer:

Code: Select all

bad argument #1 to 'soundPlay' (userdata expected, got nil)
I try everything I think, but i cant get it works fine. What i'm doing wrong?. Please help me.

Re: sounds

Posted: Mon Sep 12, 2011 12:07 am
by Administrator
It isn't loading the resource. You probably have it in the wrong directory. Try:

Code: Select all

printf("Sound path: " .. getExecutionPath() .. "/alarm.wav\n");
And make sure it is the right directory.

Re: sounds

Posted: Mon Sep 12, 2011 6:35 am
by Ajoir
I found the problem. I maked an error installing your files (sorry, was my fault. :s).
But i can not get works fine. the command that you gave me, turns

Code: Select all

C:/micromacro/scripts/rom/alarm.wav".
" The file alarm.wav is in the correct folder. In really, I still have the file in every folders. Now the bot works, but this command:

Code: Select all

"soundPlay(soundresource)"  
haven't any effect, any sound. The command "soundPlay" doesn't stop the bot. Could you help me?

Re: sounds

Posted: Mon Sep 12, 2011 7:43 am
by Administrator
So, what you're saying is you completely disregarded the big blue text at the top of this forum that says this is not the place to discuss RoMbot and decided to do so anyways? You're in the wrong place.

http://www.solarstrike.net/phpBB3/viewforum.php?f=21

Re: sounds

Posted: Mon Sep 12, 2011 8:39 am
by Ajoir
oh... I'm terribly sorry, I don't knew it.