🎡 Python sound notifications made easy

Overview

chime

Python sound notifications made easy.


Table of contents

Motivation

I made this because I wanted a simple auditory cue system to tell me when a long-running number crunching script had finished. I didn't want to have to fiddle with the command-line, and also wanted a cross-platform solution. Thus was born chime!

Installation

pip install chime

This library has no dependencies. The IPython/Jupyter functionality is only imported if you've installed the ipython library. It should work for any Python version above or equal to 3.6.

Basic usage

chime puts four functions at your disposal:

>>> import chime

>>> chime.success()
>>> chime.warning()
>>> chime.error()
>>> chime.info()

Calling any of the above functions will play a sound. Note that the sounds are played in asynchronous processes, and are thus non-blocking. Each function should take around 2ms to execute, regardless of the sound length. You're free to use each sound notification in any way you see fit. I'm not your mama.

Theming

The sounds that are played depend on which theme is being used.

>>> chime.theme()  # return the current theme
'chime'

Several themes are available:

>>> chime.themes()
['big-sur', 'chime', 'mario', 'material', 'zelda']

The theme can be changed by passing a theme name to the theme function:

>>> chime.theme('zelda')

A couple of things to note:

  • You can listen to the sounds interactively via this soundboard, which is made with Streamlit.
  • A random theme will be picked each time you play a sound if you set the theme to 'random'.

IPython/Jupyter magic

Load the extension as so:

%load_ext chime

You can wrap a line:

%chime print("I'm a line")

You can also wrap an entire cell:

%%chime

print("I'm a cell")

The magic command will call chime.success when the line/cell finishes successfully. Otherwise, chime.error is called whenever an exception is raised.

Exception notifications

If you run chime.notify_exceptions, then chime.error will be called whenever an exception is raised.

chime.notify_exceptions()

raise ValueError("I'm going to make some noise")

Command-line usage

You can run chime from the command-line:

$ chime

By default, this will play the success sound. You can also choose which sound to play, like so:

$ chime info

You can also choose which theme to use:

$ chime info --theme zelda

If you're using bash, then you can use chime to notify you when a program finishes:

$ echo "Hello world!"; chime

This will play the sound regardless of the fact that the first command succeeded or not. If you're running on Windows, then you can run the following equivalent:

> echo "Hello world!" & chime

Platform support

Under the hood, chime runs a command in the shell to play a .wav file. The command-line program that is used depends on the platform that you're using. Platform information is available in the sys.platform variable as well as the platform module from the standard library. Currently, the supported platforms are:

  • Darwin
  • Linux
  • Windows

A UserWarning is raised if you run a chime sound on an unsupported platform. Feel free to get in touch or issue a pull request if you want to add support for a specific platform. Likewise, don't hesitate if you're encountering trouble with one of the above platforms. I won't bite.

I can't hear anything πŸ™‰

Did you check if you turned your sound on? Just kidding. 😜

This library is designed to be non-invasive. By default, sounds are played asynchronously in unchecked processes. Therefore, if something goes wrong, the process dies silently. If you can't hear anything and you think that the issue is coming from chime, then set the sync parameter when you play a sound:

>>> chime.info(sync=True)

This will play the sound synchronously and issue a warning if something goes wrong, which should allow you to debug the issue. You can also raise an exception instead of sending a warning by setting the raise_error parameter:

>>> chime.info(sync=True, raise_error=True)

Note that setting raise_error won't do anything if sync is set to False.

Setting a default theme

To change the default theme a configuration file may be created in ~/.config/chime/chime.conf on Unix or %APPDATA%\chime\chime.ini on Windows.

For example, to change the default theme to 'zelda' the configuration file would contain:

[chime]
theme = zelda

Adding a new theme

I have toyed with the idea of allowing users to add their own theme(s), but at the moment I rather keep things minimal. However, I'm happy to integrate new themes into the library. You can propose a new theme by opening a pull request that adds the necessary .wav files to the themes directory. A theme is made up of four files: success.wav, warning.wav, error.wav, and info.wav. Be creative! πŸ‘©β€πŸŽ¨

Things to do

  • Some mechanism to automatically call chime.warning when a warning occurs.
  • Make it work with a remote machine. For instance a Jupyter Notebook hosted on a remote machine.
  • More themes!

Acknowledgements

  • Special thanks to Michael Vlah for being a gentleman by giving up the "chime" name on PyPI.
  • Thanks to u/Pajke on reddit for helping me debug Windows support.
  • Thanks to David Chen for adding Linux support by suggesting the use of aplay.
  • Thanks to Vincent Warmerdam for suggesting a command-line interface.
  • Calmcode made a video introduction to chime ❀️
  • Thanks to Paulo S. Costa for contributing in many different ways.
  • Thanks to d34d_m8 for adding OpenBSD support.

License

As you would probably expect, this is MIT licensed.

Comments
  • Add the ability to set the default theme through a configuration file

    Add the ability to set the default theme through a configuration file

    This PR adds the ability to set the default theme via a configuration file.

    The location is set on ~/.config/chime/chime.conf on Unix or %APPDATA%\chime\chime.ini on Windows.

    The format of the configuration file is:

    [chime]
    theme = zelda
    
    

    Two unit tests have been added that test the detection of the config file location based on platform and test that chime changes its default theme based on the config file.

    Closes #13

    opened by paw-lu 10
  • Add a `chime` command for cli usage

    Add a `chime` command for cli usage

    Cool library!

    Would be great if we named the command so you could call the script from the command line using

    % chime
    

    instead of having to use

    % python -m chime
    

    This would also allow users to install the library using installers like pipx if they were interested in using it as a command-line tool.

    opened by paw-lu 8
  • Can't hear any sounds on Pop! OS 20.04

    Can't hear any sounds on Pop! OS 20.04

    Steps I took

    • install in venv with pip3 install chime
    • open python3 shell
    • import chime and run chime.success()
    • can't hear anything at all (no other audio is playing, audio is definitely working)

    I can definitely help test some stuff if needed!

    opened by dchen327 7
  • No sound, error:

    No sound, error: "aplay: not found"

    Hey there, I love chime! I'm having troubles running it on a remote server. This is what I get when I call chime.info(sync=True, raise_error=True):

    RuntimeError: Command 'aplay /home/mgrasso/miniconda3/envs/pyphi/lib/python3.7/site-packages/themes/zelda/info.wav' returned non-zero exit status 127. stderr: /bin/sh: 1: aplay: not found

    Any tips? Thanks in advance, MG

    opened by matteograsso 6
  • Add a material theme

    Add a material theme

    The Material design resource page has some high quality notification sounds licensed under Creative Commons. It would make a great theme for some more typical notification sounds.

    opened by paw-lu 2
  • Add the ability to set the default theme through a configuration file

    Add the ability to set the default theme through a configuration file

    This PR adds the ability to set the default theme via a configuration file.

    The location is set on ~/.config/chime/chime.conf on Unix or %APPDATA%\chime\chime.ini on Windows.

    The format of the configuration file is:

    [chime]
    theme = zelda
    
    

    Two unit tests have been added that test the detection of the config file location based on platform and test that chime changes its default theme based on the config file.

    Closes #13

    opened by paw-lu 1
  • Add a material theme

    Add a material theme

    The Material design resource page has some high quality notification sounds licensed under Creative Commons. This PR selects four of those sounds and adds a material theme to chime.

    Additionally this PR:

    • Adds a test that each theme contains all four events (error, info, success, and warning)
    • A LICENSE with attribution for the sounds
    • Modifies the example output for chime.themes() in README.md to include the material theme.

    Closes #12

    opened by paw-lu 1
  • Install package in workflows before running test

    Install package in workflows before running test

    This PR changes the test workflows. The workflows now:

    1. Install Poetry
    2. Use Poetry to install the package and dependencies, including pytest
    3. Use Poetry to run pytest

    This fixes the failing tests caused by #6 πŸ˜….

    Closes #9

    constraints.txt

    An additional opinionated change I made is lock the Poetry version by specifying it in .github/workflows/constraints.txt. This would prevent surprise CI failures in the future if Poetry has further breaking changes. This will also prevent the CI from always installing the latest version of Poetry. The Poetry version in the CI must then be upgraded by bumping the version in .github/workflows/constraints.txt either manually or with GitHub's Dependabot. I am also happy to help on the Dependabot end if wanted.

    Of course, if this is too strict and complex, we can remove constraints.txt and let the workflow always install the latest version of Poetry.

    opened by paw-lu 1
  • Support Poetry >=1.1.0

    Support Poetry >=1.1.0

    opened by paw-lu 1
  • Add `chime` script

    Add `chime` script

    This PR:

    • Moves the CLI functionality to the function main
    • Adds a script under the command chime
    • Adds a unit test testing the new command
    • Updates the command-line sections in the README from python -m chime β†’ chime

    After installing the library, this PR would allow a user to use chime by running

    % chime
    

    in their terminal.

    Closes #5

    opened by paw-lu 1
  • Install package in GitHub workflows before running tests

    Install package in GitHub workflows before running tests

    The test workflow is failing after #6 because the workflow does not install the package. The workflow should install the package itself before running tests.

    opened by paw-lu 0
  • Add chime to Conda/Anaconda command line actions

    Add chime to Conda/Anaconda command line actions

    I have raised an Feature Request here with Conda/Anaconda to add this as an option on installs/creates etc. I haven't given it any though, but maybe there is a wrapper or call that can be made before a conda command that can make these alerts. Thought I'd raise it here to see if it was a valid idea!

    Motivations - The number of times I have forgotten the -y argument and been pending on a large install is terrifying!

    V cool package btw! Thx

    opened by JoshuaC3 1
  • [enhancement] exit code parameter for cli

    [enhancement] exit code parameter for cli

    Been thinking of a way to automatically trigger success/error sounds based on whether the previous command succeeded on the terminal.

    One way to accomplish this would be an --exit-code (-e) argument to be used as such:

    % ls; chime --exit-code=$?
    

    $? in bash and zsh stores the exit code of the previous command. An exit-code argument would allow the user to input it into chime, triggering an error on a non-zero exit code, success otherwise.

    To be honest I wish there was a more automated way to handle this, but this is the best I can come up with at the moment!

    opened by paw-lu 2
Owner
Max Halford
Going where the wind blows πŸƒ πŸ¦”
Max Halford
A python script that can play .mp3 URLs upon the ringing or motion detection of a Ring doorbell. The sound plays through Sonos speakers.

Ring x Sonos A python script that plays .mp3 files whenever a doorbell is rung or a doorbell detects motion. Features Music! Authors @braden Running T

braden 0 Nov 12, 2021
A simple python script to play bell sound in your system infinitely, just for fun and experimental purposes

A simple python script to play bell sound in your system infinitely, just for fun and experimental purposes

نافع Ψ§Ω„Ω‡Ω„Ψ§Ω„ΩŠ 1 Oct 29, 2021
PyAbsorp is a python module that has the main focus to help estimate the Sound Absorption Coefficient.

This is a package developed to be use to find the Sound Absorption Coefficient through some implemented models, like Biot-Allard, Johnson-Champoux and

Michael Markus Ackermann 8 Oct 19, 2022
GNOME powered sound conversion

SoundConverter A simple sound converter application for the GNOME environment. It reads anything the GStreamer library can read, and writes Ogg Vorbis

Gautier Portet 188 Dec 17, 2022
Graphical interface to control granular sound synthesis.

Granular sound synthesis interface SoundGrain is a graphical interface where users can draw and edit trajectories to control granular sound synthesis

Olivier BΓ©langer 122 Dec 10, 2022
Open Sound Strip, Sequence or Record in Audacity

Audacity Tools For Blender Sound editing in Blender Video Sequence Editor with Audacity integrated. Send/receive the full edited sequence or single st

null 64 Dec 31, 2022
Reading list for research topics in sound event detection

Sound event detection aims at processing the continuous acoustic signal and converting it into symbolic descriptions of the corresponding sound events present at the auditory scene.

Soham 64 Jan 5, 2023
extract unpack asset file (form unreal engine 4 pak) with extenstion *.uexp which contain awb/acb (cri/cpk like) sound or music resource

Uexp2Awb extract unpack asset file (form unreal engine 4 pak) with extenstion .uexp which contain awb/acb (cri/cpk like) sound or music resource. i ju

max 6 Jun 22, 2022
Analyze, visualize and process sound field data recorded by spherical microphone arrays.

Sound Field Analysis toolbox for Python The sound_field_analysis toolbox (short: sfa) is a Python port of the Sound Field Analysis Toolbox (SOFiA) too

Division of Applied Acoustics at Chalmers University of Technology 69 Nov 23, 2022
Library for working with sound files of the format: .ogg, .mp3, .wav

Library for working with sound files of the format: .ogg, .mp3, .wav. By work is meant - playing sound files in a straight line and in the background, obtaining information about the sound file (author, performer, duration, bitrate, and so on). Playing goes through the pygame, and getting information through the mutagen.

Romanin 2 Dec 15, 2022
An app made in Python using the PyTube and Tkinter libraries to download videos and MP3 audio.

yt-dl (GUI Edition) An app made in Python using the PyTube and Tkinter libraries to download videos and MP3 audio. How do I download this? Windows: Fi

null 1 Oct 23, 2021
voice assistant made with python that search for covid19 data(like total cases, deaths and etc) in a specific country

covid19-voice-assistant voice assistant made with python that search for covid19 data(like total cases, deaths and etc) in a specific country installi

Miguel 2 Dec 5, 2021
A Quick Music Player Made Fully in Python

Quick Music Player Made Fully In Python. Pure Python, cross platform, single function module with no dependencies for playing sounds. Installation & S

null 1 Dec 24, 2021
Synthesia but open source, made in python and free

PyPiano Synthesia but open source, made in python and free Requirements are in requirements.txt If you struggle with installation of pyaudio, run : pi

DaCapo 11 Nov 6, 2022
Manipulate audio with a simple and easy high level interface

Pydub Pydub lets you do stuff to audio in a way that isn't stupid. Stuff you might be looking for: Installing Pydub API Documentation Dependencies Pla

James Robert 6.6k Jan 1, 2023
DCL - An easy to use diacritic library used for diacritic and accent manipulation.

Diacritics Library This library is used for adding, and removing diacritics from strings. Getting started Start by importing the module: import dcl DC

Kreus Amredes 6 Jun 3, 2022
DeepMusic is an easy to use Spotify like app to manage and listen to your favorites musics.

DeepMusic is an easy to use Spotify like app to manage and listen to your favorites musics. Technically, this project is an Android Client and its ent

Labrak Yanis 1 Jul 12, 2021
An 8D music player made to enjoy Halloween this year!🀘

HAPPY HALLOWEEN buddy! Split Player Hello There! Welcome to SplitPlayer... Supposed To Be A 8DPlayer.... You Decide.... It can play the ordinary audio

Akshat Kumar Singh 1 Nov 4, 2021
cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python

audioread Decode audio files using whichever backend is available. The library currently supports: Gstreamer via PyGObject. Core Audio on Mac OS X via

beetbox 419 Dec 26, 2022