0

我按照指南(可以在http://sree.cc/corona-sdk/detect-microphone-volume-blowing-into-microphone找到)尝试检测麦克风音量。

我使用的代码是:

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 )

问题是控制台在第 7 行返回“',' 附近的意外符号”。

我试图修改代码:

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 )

但随后控制台在最后一行返回相同的错误(','附近的意外符号)(“Runtime:addEventListener(“enterFrame”,soundDetector)“)

我能做些什么来解决这个问题?

4

1 回答 1

0

In the line:

Runtime:addEventListener( “enterFrame”, soundDetector )

the quotes around enterFrame are not ASCII double quotes. The correct line should be:

Runtime:addEventListener( "enterFrame", soundDetector )

probably cut&paste from another source (a PDF document?) triggered an automatic substitution somewhere. The same problem appears to be the error cause in the first snippet you posted:

local text_ = display.newText(“Initial…”,200,10,nil,30)

versus:

local text_ = display.newText("Initial…",200,10,nil,30)

P.S.: your code is horribly formatted.

于 2013-09-13T17:14:44.910 回答