Skip to main content

Lightweight Pythonic cross-platform audio playback library

Project description

pysoniq

Minimal Pythonic cross-platform audio analysis and playback library.

  • Cross-platform - Windows, macOS, Linux
  • Minimal dependencies - numpy, scipy, wave, ffmpeg
  • Simple API - Play, pause, stop, loop

Installation

pip install pysoniq

WIP: For MP3 support, install ffmpeg: https://ffmpeg.org/

Use in context

import pysoniq
import numpy as np
import wave

# Play WAV file
pysoniq.play('audio.wav')

# Play as numpy array
sr = 44100
t = np.linspace(0, 1.0, sr)
audio = 0.3 * np.sin(2 * np.pi * 440 * t)
pysoniq.play(audio, samplerate=sr)

# Loop playback
pysoniq.set_loop(True)
pysoniq.play(audio, sr)

# Stop
pysoniq.stop()

# Make audio blobs for model input
X, y = make_audioblobs(
    source       = "path/to/wav_dir",
    n_fft        = 512,
    metric       = "euclidean",
    n_classes    = 10,
    random_state = 42,
    verbose      = True,
)

Features

Playback

pysoniq.play(data, samplerate)   # Play audio
pysoniq.stop()                   # Stop playback
pysoniq.pause()                  # Pause
pysoniq.resume()                 # Resume

Looping

pysoniq.set_loop(True)   # Enable loop
pysoniq.is_looping()     # Check status

Gain Control

pysoniq.set_gain(0.5)           # 50% volume
pysoniq.set_volume_db(-6.0)     # Set dB
audio = pysoniq.adjust_gain_level(audio, 1.5)

Audio I/O

audio, sr = pysoniq.load_audio('file.wav')  # or .mp3
pysoniq.save_audio('output.wav', audio, sr)

Fourier Analysis

import pysoniq.fourier as pf

S = pf.magnitude_stft(audio, n_fft=2048)
S_db = pf.amplitude_to_db(S)

Platform Requirements

  • Windows: Built-in (winsound)

  • macOS: Built-in (afplay)

  • Linux: ALSA (aplay) - usually pre-installed

  • MP3: ffmpeg (install separately)

Limitations

  • mp3 support is WIP
  • Pause/resume uses time-based estimation
  • Gain changes apply on next loop iteration

License

MIT

Author

laelume

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysoniq-0.1.8.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysoniq-0.1.8-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file pysoniq-0.1.8.tar.gz.

File metadata

  • Download URL: pysoniq-0.1.8.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pysoniq-0.1.8.tar.gz
Algorithm Hash digest
SHA256 24585ed0ae22bf5e5799cd493da06cb40af40e7a9aaa5591d007c8ff017bcd27
MD5 195aadec880d5a451d1609d2f6af691a
BLAKE2b-256 2492fc14e1b516d92f6d7002b22f712b979c48426a292260ebbb7db50796163f

See more details on using hashes here.

File details

Details for the file pysoniq-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pysoniq-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pysoniq-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 49c6557be34134cf37add852d6e704272ebcec601d602893fc21ade85892b643
MD5 dfc1552ebb1e0446232400ed56538620
BLAKE2b-256 cb11d3a208ffc390708eb790a7adf4063a5526d1adea9b0c0febf73e494a9d22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page