Hi you all, I followed a guide (that can be found at http://sree.cc/corona-sdk/detect-microphone-volume-blowing-into-microphone) to try to detect the microphone volume.
The code I’ve used is:
[lua]
local _w = display.contentWidth
local _h = display.contentHeight
local background_ = display.newRect(0,0,_w,_h)
background_:setFillColor(255)
local text_ = display.newText(“Initial…”,200,10,nil,30)
text_:setTextColor(0)
local r = media.newRecording()
r:startRecording()
r:startTuner()
function soundDetector( event )
local v = r:getTunerVolume()
if v == 0 then
return
end
v = 20 * 0.301 * math.log(v)
m = v*10
if(m>= -50)then
text_.text = “High…”
background_:setFillColor(255,0,0)
elseif(m< -50 and m>-100)then
text_.text = “Medium…”
background_:setFillColor(0,0,255)
else
text_.text = “Low…”
background_:setFillColor(0,255,0)
end
end
Runtime:addEventListener( “enterFrame”, soundDetector )
[/lua]
the problem is that the console returns “Unexpected symbol near ‘,’” at line 7.
I tried to modify the code in:
[lua]
local _w = display.contentWidth
local _h = display.contentHeight
local background_ = display.newRect(0,0,_w,_h)
background_:setFillColor(255)
local r = media.newRecording()
r:startRecording()
r:startTuner()
function soundDetector( event )
local v = r:getTunerVolume()
if v == 0 then
return
end
v = 20 * 0.301 * math.log(v)
m = v*10
if(m>= -50)then
background_:setFillColor(255,0,0)
elseif(m< -50 and m>-100)then
background_:setFillColor(0,0,255)
else
background_:setFillColor(0,255,0)
end
end
Runtime:addEventListener( “enterFrame”, soundDetector )
[/lua]
but then the console returns the same error (Unexpected symbol near ‘,’) at the last line (“Runtime:addEventListener( “enterFrame”, soundDetector )”)
What can I do to fix this issue? thanks!