audio.record.start( file, format, [channels], [samplerate], [bitrate] ) method


Starts a new audio recording session.

Notes

  • Only one audio recording session is supported.
  • If an audio recording session is already running, it will be stopped before the new one starts.

Parameters

file

A File or a filename as a string representing the file to save audio data to.

format

An optional string that indicates the audio encoding format of the specified file :

  • "wav": audio format known for its high-quality sound and large file size (default).
  • "mp3": widely-used compressed audio format that balances good sound quality and small file size.
  • "aac": compressed audio format offering better sound quality than MP3 at similar bit rates.

[channels]

An optional number indicating the number of channels that will be recorded, defaulting to 2.

[samplerate]

An optional number indicating the number of channels that will be recorded, defaulting to 44100.

[bitrate]

An optional number indicating the amount of data processed per unit of time in the audio file, defaulting to :

  • WAV format : 0
  • MP3 format : 128
  • AAC format : 96

Return value

This function returns a boolean value, which indicates whether the recording session started successfully.

Example

local audio = require "audio" io.write("Recording audio for 5 sec... ") -- Start audio recording audio.record.start("sound.wav", "wav") -- Wait for 5 sec during recording sleep(5000) -- Stops audio recording audio.record.stop() print("done !\n\nPlaying...") -- Plays the recorded audio file audio.Sound("sound.wav"):play():wait()