_SoundRecord

声音录制类 全部展开

只读属性展开

  • + length : int

    录制完成后的声音长度,单位ms。

  • + position : int

    当前声音录制的位置。单位ms。

  • + recording : bool

    是否正在录制声音。

公共方法展开

  • + function getBuffer() : string

    返回录制声音buffer

    • 示例

       sr:getBuffer()
  • + function save(resname : string)

    保存录制的声音到文件。

    • 参数
    • resname : 文件名
    • 示例

       sr:save('record.mp3')
  • + function start()

    开始录制声音

  • + function stop()

    结束录制声音

    • 示例

       sr:stop()

代码示例

    local sr = _SoundRecord.new( )

    _app:onIdle(function(e)
        local s = 'Record Enable: '..( _sd.recordEnable and 'true' or 'false' )
        s = s .. ' Position: ' .. sr.position .. '(ms)'
        _rd.font:drawText(0, 0, s)
        
        s = sr.recording and 'Press Key 2 to stop record' or 'Press Key 1 to begin record'
        _rd.font:drawText(0, 20, s)
        
        if sr.length > 0 then
            s = 'Press Key 3 to play record'
            _rd.font:drawText(0, 40, s)
        end
    end)

    _app:onKeyDown(function(key)
        if key==_System.Key1 then
            sr:start( )
        elseif key==_System.Key2 then
            sr:stop( )
        elseif key==_System.Key3 then
            _sd.masterGroup:play( sr )
        elseif key==_System.Key4 then
            _sd.masterGroup:playBuffer( sr:getBuffer() )
        elseif key==_System.Key5 then
            sr:save('record.wav')
        elseif key==_System.Key6 then
            _sd.masterGroup:play('record.wav')
        end
    end)
问题反馈(登录才可以发表哦!)