繁体   English   中英

无法检测麦克风音量

[英]Unable to detect microphone volume

我遵循了一个指南(可以在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”“)返回相同的错误(','附近的意外符号)

我该怎么做才能解决此问题?

在该行中:

Runtime:addEventListener( “enterFrame”, soundDetector )

enterFrame周围的引号不是ASCII双引号。 正确的行应为:

Runtime:addEventListener( "enterFrame", soundDetector )

可能是从其他来源(PDF文档?)剪切和粘贴触发了某处的自动替换。 相同的问题似乎是您发布的第一个代码段中的错误原因:

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

与:

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

PS:您的代码格式可怕。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM