簡體   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