audio · Play and record sound

Plays and stops mp3 and wav audio files and records sound with the microphone.

Class: Audio

class openpibo.audio.Audio[source]

Bases: object

Functions: play() stop() record()

Plays and stops mp3 and wav audio files.

play(filename, volume=80, background=True, volume2=1.0)[source]

Plays an mp3 or wav file

Parameters:
  • filename (str) – Audio file path (mp3, wav)

  • volume (int) – Sets the volume. (0~100)

  • background (bool) – Whether to run in the background

  • volume2 (float) – Adjusts the individual volume. (ratio, 0.0~3.0)

stop()[source]

Stops the audio being played

record(filename, timeout=5, verbose=True)[source]

Records sound from the microphone.

It uses only the channel that has sound, drops the noisy start of the recording (it records that much longer), removes hum and hiss, and normalizes the level before saving.

Parameters:
  • filename (str) – Path to save the recorded file. The extension (wav · mp3) sets the format

  • timeout (int) – Recording time (s). A number greater than 0

Raises:

RuntimeError – If no microphone is found or the file cannot be saved