Python Glossary Русский

all Python 3until 3.13LinuxRemoved from the standard libraryterm

ossaudiodev

removed modules

Access to the sound card through OSS (/dev/dsp). Linux-only. Removed in Python 3.13 with no stdlib replacement — use pygame or sounddevice.

Syntax

import ossaudiodev  # до 3.13

ossaudiodev.open('w') opened /dev/dsp, setfmt() and setparameters() set the format, write() sent samples to the sound card. It worked on Linux and FreeBSD. PEP 594 dropped it: OSS was replaced by ALSA and PulseAudio back in the 2000s, and modern systems usually have no /dev/dsp device. There is no stdlib replacement: for playback What's New 3.13 suggests pygame, and sounddevice or simpleaudio also work. If you only need to save the sound, write it to a .wav file with the wave module and play it with any player.

Examples

# Python 3.13+
try:
    import ossaudiodev
except ModuleNotFoundError as e:
    print(type(e).__name__)  # → ModuleNotFoundError
# Python 3.13+
import math, struct, wave
frames = b''.join(struct.pack('<h', int(8000 * math.sin(i / 10))) for i in range(800))
with wave.open('beep.wav', 'wb') as w:
    w.setparams((1, 2, 8000, 0, 'NONE', 'not compressed'))
    w.writeframes(frames)
with wave.open('beep.wav', 'rb') as r:
    print(r.getnframes())  # → 800

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy