class Recorder

The recorder can record audio from the microphone and encode the audio into wav or amr format.

class audio.Recorder

Constructors

class audio.Recorder(sample=8000, bits=16, stereo=False)

Create a Recorder object.

Parameters:
  • sample (int) – The sample rate of the audio data. The range is 8000-96000.

  • bits (int) – The bits of the audio data.

  • stereo (bool) – Whether the audio data is stereo.

UIFLOW2:

init.png

Methods

Recorder.record(uri: str, time: int, sync=True)

Record audio from microphone to file.

Parameters:

UIFLOW2:

record_local_file.png

record_sdcard_file.png

Recorder.create_pcm_buf(time) bytearray

Create a buffer to store the audio data. The audio data is in PCM format.

The length of the data buffer is \(sample * bits * time / 8\)

Parameters:

time (int) – The duration of the recording, The unit is seconds.

Returns:

The buffer to store the audio data.

UIFLOW2:

create_pcm_buf.png

Recorder.record_into(buf, sample=8000, bits=16, stereo=False, sync=True)

Play the raw audio data.

Parameters:
  • buf (bytes) – Read into buf from the microphone.

  • sample (int) – The sample rate of the audio data. The range is 8000-96000.

  • bits (int) – The bits of the audio data.

  • stereo (bool) – Whether the audio data is stereo.

  • sync (bool) – Whether to record synchronously.

UIFLOW2:

record_into.png

Recorder.pause()

Pause the Recorder.

UIFLOW2:

pause.png

Recorder.resume()

Resume the Recorder.

UIFLOW2:

resume.png

Recorder.stop()

Stop the Recorder.

UIFLOW2:

stop.png

Recorder.rms() float

Get the root mean square of the audio data.

Returns:

The root mean square of the audio data. The unit is dB.

UIFLOW2:

rms.png

Recorder.volume() int

Get the volume of the audio data.

Returns:

The volume of the audio data. The range is 0-100.

UIFLOW2:

volume.png

Recorder.is_recording() bool

Check if the Recorder is recording.

Returns:

True if the Recorder is recording, False otherwise.

UIFLOW2:

is_recording.png

Recorder.config(sample=8000, bits=16, stereo=False) bool

Configure the Recorder.

Parameters:
  • sample (int) – The sample rate of the audio data. The range is 8000-96000.

  • bits (int) – The bits of the audio data.

  • stereo (bool) – Whether the audio data is stereo.

UIFLOW2:

config.png