It is currently April 26th, 2024, 1:06 am

Play Sounds from a lua script

Get help with creating, editing & fixing problems with skins
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Play Sounds from a lua script

Post by hashtaghashtag9967 »

Hi, i have made a little siri-like "ai" (with a WAY FEWER capabilities) it basically responds to user input then responds or opens a application, I want to give it a voice, now i know the play command thingy exists but to my knowledge it cant be put in the lua code (or it can and im just bad at this) so is there any way to implement a lot of different sounds on one skin taking input from lua script? thanks in advance :D


heres my lua code if it helps:

Code: Select all

function DealWithInput(inArg)

   inputText = string.lower(inArg)

	if inputText == 'hi' then outputText = 'ugh i was sleeping -_-'
		elseif inputText == 'hello' then outputText = 'hello user'
		elseif inputText == 'open chrome' then outputText = 'nope, i dont wanna'
		elseif inputText == 'who is the best programmer' then outputText = 'ill give you a hint... its not you'
		elseif inputText == 'thats not nice'then outputText = 'does it look like i care???'
		elseif inputText == 'that is not nice'then outputText = 'does it look like i care???'
		elseif inputText == 'you dont understand much'then outputText = 'says the ape using me for info'
		elseif inputText == 'open firefox'then SKIN:Bang('!execute ["https://www.google.com/"]') outputText = 'why would i set a fox on fire? you monster!'
		elseif inputText == 'search'then SKIN:Bang('!execute ["https://www.google.com/"]') outputText = 'B.i.n.g. Because Its Not Google'
		elseif inputText == 'chess'then SKIN:Bang('!execute ["https://lichess.org/"]') outputText = 'Would you like to play a game of thermo nuclear war?'
		elseif inputText == 'files'then SKIN:Bang('!Execute ["C:"]') outputText = 'please dont delete me 0_0 ill be nice... *crosses fingers*'
		elseif inputText == 'task'then os.execute("control access.cpl") outputText = 'the computer runs slow cause it dosent like you'
		elseif inputText == 'give meh candy'then outputText = 'no your fat'
		elseif inputText == 'tell me a joke'then outputText = 'School'
		elseif inputText == 'what does pun mean'then outputText = 'Personal Unit for Navigation of tech. If you must know'
		elseif inputText == 'what does PUN mean'then outputText = 'Personal Unit for Navigation of tech. If you must know'
		elseif inputText == 'what dose pun mean'then outputText = 'Personal Unit for Navigation of tech. If you must know'
		elseif inputText == 'what dose PUN mean'then outputText = 'Personal Unit for Navigation of tech. If you must know'  
		elseif inputText == 'im bored'then outputText = 'good for you guess who is a digital minion to a idiot all day???'
		elseif inputText == 'test'then SKIN:Bang('Play "F:\rainmeter sounds\test.wav"')

------ this line isnt working ^^^^ so i asume i cant put it in here?
		
		
		else outputText = 'I dont understand that yet... sorry (not sorry)'
	
	
	
	end
   

   SKIN:Bang('!SetOption', 'RESPONDINGTEXT', 'Text', outputText)
   SKIN:Bang('!UpdateMeter', 'RESPONDINGTEXT')
   SKIN:Bang('!Redraw')

end
And here is the rainmeter ini

Code: Select all

[Rainmeter]
Update=50
DynamicWindowSize=1

[Variables]
FontSize=14

[MeasureScript]
Measure=Script
ScriptFile=textchecker.lua
Disabled=1


[EyeScript]
Measure=Script
ScriptFile=eye.lua



[ModeScript]
Measure=Script
ScriptFile=modegetscript.lua


[MeterBackground]
Meter=Image
ImageName=E:\CustomRainfinalfile\punbackround.png

W=500
H=500

[PUNFACE]
meter=image
ImageName=E:\CustomRainfinalfile\punface.png
W=190
H=150
Y=120

[PUNEYE]
meter=image
ImageName=E:\CustomRainfinalfile\puneye.png
W=190
H=100
Y=150


[MeterBackgroundhomemode]
Meter=Image
ImageName=F:\CustomRainfinalfile\punbackround.png

W=500
H=500

[PUNFACEhomemode]
meter=image
ImageName=F:\CustomRainfinalfile\punface.png
W=190
H=150
Y=120

[PUNEYEhomemode]
meter=image
ImageName=F:\CustomRainfinalfile\puneye.png
W=190
H=100
Y=150



[RESPONDINGTEXT]
Meter = string
FontSize=15
X=0
Y=280
W=200
H=80
ClipString=1
FontColor=7,198,185
TEXT=Ugh what do you want now human???

[MeterPrompt]
Meter=String
X=5
Y=350
FontSize=15
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=Speak to P.U.N.
LeftMouseUpAction=[!SetOption RESPONDINGTEXT Text "What do you want now???"][!UpdateMeter RESPONDINGTEXT][!Redraw][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=76A0E8FF
FontColor=255,255,255,255
FontFace=Seqoe UI
StringStyle=Italic
FontSize=#FontSize#
X=5
Y=350
H=25
W=200
OnDismissAction=[!SetOption RESPONDINGTEXT Text "Welcome"][!UpdateMeter RESPONDINTEXT][!Redraw]
Command1=[!CommandMeasure MeasureScript "DealWithInput('$UserInput$')]
Last edited by Brian on August 31st, 2017, 2:35 am, edited 1 time in total.
Reason: Please use [code] tags
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Play Sounds from a lua script

Post by jsmorley »

You are missing a space, and missing it in almost all your if / then statements.

elseif inputText == 'test' then SKIN:Bang('Play "F:\rainmeter sounds\test.wav"')

Do be careful though, if the result is "test", you are not setting outputText at all. You might want to do both.

P.S. You are using string.lower() as you should, but then you are not taking advantage of it: If I fix the missing spaces:

elseif inputText == 'what does pun mean' then outputText = 'Personal Unit for Navigation of tech. If you must know'
elseif inputText == 'what does PUN mean' then outputText = 'Personal Unit for Navigation of tech. If you must know'

Nothing with any capital letters will ever match.

You are changing the user's input to lower case, so in that example only one:

elseif inputText == 'what does pun mean' then outputText = 'Personal Unit for Navigation of tech. If you must know'

Is needed.
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Re: Play Sounds from a lua script

Post by hashtaghashtag9967 »

Thanks for your reply, but the new code didn't seem to fix the problem however now instead of making no noise it makes the iconic windows error sound (witch is not the sound file) and brings up no error box. so im assuming somthing is going wrong behind the scenes do you have any idea what that noise would mean. also the rainmeter log thing reveals no errors partaining to this problem

this is the new line of code:

elseif inputText == 'test' then SKIN:Bang('Play "F:\rainmeter sounds\test.wav"') outputText = 'test success'


the text part works
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Play Sounds from a lua script

Post by jsmorley »

I struggled for a bit with this myself. In fact, I posted a terrible work-around a while ago that I deleted. I have found the issue now though...

The problem is the "\" in Windows paths is also the "escape" character in Lua strings. It's why you can do \n to get a linefeed in a string. You will need to escape the "\" with another "\" to get it to work as a literal.

elseif inputText == 'test' then SKIN:Bang('Play "F:\\rainmeter sounds\\test.wav"') outputText = 'test success'

https://www.tutorialspoint.com/lua/lua_strings.htm
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Re: Play Sounds from a lua script

Post by hashtaghashtag9967 »

thank you ! Your the best!, ps thanks for the capital test fix earlier u put that in the ai code on my previous question and I didn't know what it did :D