我不知道该走哪条路才能让 NodeMCU 播放音频。我想使用一到两秒的 wav 文件并驱动一个微型扬声器。目标是听到人声,而不是超高保真度。另外,我不想使用音频屏蔽或 SD 卡。我的文件足够小,可以直接从芯片运行所有内容。无需录制样本,只需回放即可。我应该使用什么?有什么例子吗?看来 sigma-delta 模块是一个很好的起点。
最佳答案
一次https://github.com/nodemcu/nodemcu-firmware/pull/1255已登陆 dev
分支,您可以执行以下操作 as documented :
-- ****************************************************************************
-- Play file with pcm module.
--
-- Upload jump_8k.u8 to spiffs before running this script.
--
-- ****************************************************************************
function cb_drained(d)
print("drained "..node.heap())
file.seek("set", 0)
-- uncomment the following line for continuous playback
--d:play(pcm.RATE_8K)
end
function cb_stopped(d)
print("playback stopped")
file.seek("set", 0)
end
function cb_paused(d)
print("playback paused")
end
file.open("jump_8k.u8", "r")
drv = pcm.new(pcm.SD, 1)
-- fetch data in chunks of LUA_BUFFERSIZE (1024) from file
drv:on("data", file.read)
-- get called back when all samples were read from the file
drv:on("drained", cb_drained)
drv:on("stopped", cb_stopped)
drv:on("paused", cb_paused)
-- start playback
drv:play(pcm.RATE_8K)
Audio is expected as a mono raw unsigned 8 bit stream at sample rates between 1 k and 16 k samples per second. Regular WAV files can be converted with OSS tools like Audacity or SoX. Adjust the volume before the conversion.
关于audio - NodeMCU 播放 .wav 或 .mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36324828/