sounds

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
zuel
Posts: 21
Joined: Mon Jan 10, 2011 12:49 am

sounds

#1 Post by zuel » Mon Jan 10, 2011 12:52 am

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.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: sounds

#2 Post by Administrator » Mon Jan 10, 2011 1:59 am

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).

zuel
Posts: 21
Joined: Mon Jan 10, 2011 12:49 am

Re: sounds

#3 Post by zuel » Mon Jan 10, 2011 12:45 pm

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.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: sounds

#4 Post by Administrator » Mon Jan 10, 2011 5:00 pm

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)?

zuel
Posts: 21
Joined: Mon Jan 10, 2011 12:49 am

Re: sounds

#5 Post by zuel » Mon Jan 10, 2011 6:11 pm

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!

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: sounds

#6 Post by Administrator » Mon Jan 10, 2011 6:39 pm

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).
Attachments
micromacro.zip
MicroMacro 1.01 beta 4 experimental sound support
(432.96 KiB) Downloaded 315 times

zuel
Posts: 21
Joined: Mon Jan 10, 2011 12:49 am

Re: sounds

#7 Post by zuel » Mon Jan 10, 2011 11:56 pm

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!

Ajoir
Posts: 32
Joined: Mon May 30, 2011 1:29 pm

Re: sounds

#8 Post by Ajoir » Sun Sep 11, 2011 10:58 pm

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.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: sounds

#9 Post by Administrator » Mon Sep 12, 2011 12:07 am

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.

Ajoir
Posts: 32
Joined: Mon May 30, 2011 1:29 pm

Re: sounds

#10 Post by Ajoir » Mon Sep 12, 2011 6:35 am

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?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: sounds

#11 Post by Administrator » Mon Sep 12, 2011 7:43 am

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

Ajoir
Posts: 32
Joined: Mon May 30, 2011 1:29 pm

Re: sounds

#12 Post by Ajoir » Mon Sep 12, 2011 8:39 am

oh... I'm terribly sorry, I don't knew it.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests