nava 0.8
A Python library for playing sound everywhere natively and securely.
License: MIT
Requires Python: >=3.7
Keywords: sound wav music mp3 player audio


<div align="center">
    <img src="https://github.com/openscilab/nava/raw/main/others/logo.png" width="300">
    <h1>Nava</h1>
    <br/>
    <a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3"></a>
    <a href="https://badge.fury.io/py/nava"><img src="https://badge.fury.io/py/nava.svg" alt="PyPI version"></a>
    <a href="https://anaconda.org/openscilab/nava"><img src="https://anaconda.org/openscilab/nava/badges/version.svg"></a>
    <a href="https://codecov.io/gh/openscilab/nava"><img src="https://codecov.io/gh/openscilab/nava/branch/main/graph/badge.svg" alt="Codecov"></a>
    <a href="https://discord.gg/MCbPKCFBs3"><img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel"></a>
</div>

## Overview

<p align="justify">
Nava is a Python library that allows users to play sound in Python without any dependencies or platform restrictions. It is a cross-platform solution that runs on any operating system, including Windows, macOS, and Linux. Its lightweight and easy-to-use design makes Nava an ideal choice for developers looking to add sound functionality to their Python programs.
</p>

<table>
	<tr>
		<td align="center">PyPI Counter</td>
		<td align="center">
		    <a href="https://pepy.tech/projects/nava">
			<img src="https://static.pepy.tech/badge/nava" alt="PyPI Downloads">
		    </a>
   	       </td>
	</tr>
	<tr>
		<td align="center">Github Stars</td>
		<td align="center">
            <a href="https://github.com/openscilab/nava">
                <img src="https://img.shields.io/github/stars/openscilab/nava.svg?style=social&label=Stars">
            </a>
        </td>
	</tr>
</table>



<table>
	<tr> 
		<td align="center">Branch</td>
		<td align="center">main</td>
		<td align="center">dev</td>
	</tr>
    <tr>
		<td align="center">Linux CI</td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/linux_test.yml/badge.svg?branch=main"></td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/linux_test.yml/badge.svg?branch=dev"></td>
	</tr>
	<tr>
		<td align="center">Windows CI</td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/windows_test.yml/badge.svg?branch=main"></td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/windows_test.yml/badge.svg?branch=dev"></td>
	</tr>
	<tr>
		<td align="center">macOS CI</td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/macOS_test.yml/badge.svg?branch=main"></td>
		<td align="center"><img src="https://github.com/openscilab/nava/actions/workflows/macOS_test.yml/badge.svg?branch=dev"></td>
	</tr>
</table>

<table>
	<tr> 
		<td align="center">Code Quality</td>
		<td align="center"><a href="https://app.codacy.com/gh/openscilab/nava/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://app.codacy.com/project/badge/Grade/9c384b4e400340ae94772c1d7e1842d0"></a></td>
		<td align="center"><a href="https://www.codefactor.io/repository/github/openscilab/nava"><img src="https://www.codefactor.io/repository/github/openscilab/nava/badge" alt="CodeFactor"></a></td>
	</tr>
</table>

## Installation

### PyPI

- Check [Python Packaging User Guide](https://packaging.python.org/installing/)     
- Run `pip install nava==0.8`

### Source code
- Download [Version 0.8](https://github.com/openscilab/nava/archive/v0.8.zip) or [Latest Source](https://github.com/openscilab/nava/archive/dev.zip)
- Run `pip install .`

### Conda

- Check [Conda Managing Package](https://conda.io/)
- Update Conda using `conda update conda`
- Run `conda install -c openscilab nava`

## Usage

### Basic

```python
from nava import play
play("alarm.wav")
```

### Async mode

⚠️ The `async_mode` parameter has a default value of `False`

```python
import time
from nava import play, stop
sound_id = play("alarm.wav", async_mode=True)
time.sleep(4)
stop(sound_id)
```

### Loop mode

⚠️ The `loop` parameter has a default value of `False` 

⚠️ You should always set `async_mode` flag when you are using `loop`

```python
from nava import play, stop
sound_id = play("alarm.wav", async_mode=True, loop=True)
time.sleep(100)
stop(sound_id)
```

### Error

```python
from nava import play, NavaBaseError

try:
    play("alarm.wav")
except NavaBaseError as e:
    print(str(e))
```

### Engine

⚠️ The `engine` parameter has a default value of `AUTO` 

```python
from nava import play, Engine
sound_id = play("alarm.wav", engine=Engine.AFPLAY)
```

### CLI
```bash
$ nava [--file FILE_PATH] [--loop] FILE_PATH
```

## Engines list

List of different platforms and the corresponding engines that are used for sound playing.

<table>
	<tr> 
		<th align="center">Engine</th>
		<th align="center">Platform</th>
		<th align="center">References</th>
		<th align="center">Supported Formats</th>
	</tr>
    <tr>
		<td align="center"><code>ALSA</code></td>
		<td align="center">Linux</td>
		<td align="center"><a href="https://www.alsa-project.org/wiki/Main_Page">Advanced Linux Sound Architecture</a></td>
		<td align="center"><code>.wav</code></td>
	</tr>
    <tr>
		<td align="center"><code>WINSOUND</code></td>
		<td align="center">Windows</td>
		<td align="center"><a href="https://docs.python.org/3/library/winsound.html">Winsound</a></td>
		<td align="center"><code>.wav</code></td>
	</tr>
	    <tr>
		<td align="center"><code>WINMM</code></td>
		<td align="center">Windows</td>
		<td align="center"><a href="https://learn.microsoft.com/en-us/windows/win32/multimedia/mci-reference">Windows MCI (Media Control Interface)</a></td>
		<td align="center"><code>.wav</code>, <code>.mp3</code>, <code>.avi</code></td>
	</tr>
    <tr>
		<td align="center"><code>AFPLAY</code></td>
		<td align="center">macOS</td>
		<td align="center"><a href="https://ss64.com/mac/afplay.html">Audio File Play</a></td>
		<td align="center"><code>.wav</code>, <code>.mp3</code></td>
	</tr>
</table>


## Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [nava@openscilab.com](mailto:nava@openscilab.com "nava@openscilab.com").

- Please complete the issue template
 
You can also join our discord server

<a href="https://discord.gg/MCbPKCFBs3">
  <img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel">
</a>

## Acknowledgments

[Python Software Foundation (PSF)](https://www.python.org/psf/) grants Nava library from version **0.8** to **0.9**. [PSF](https://www.python.org/psf/) is the organization behind Python. Their mission is to promote, protect, and advance the Python programming language and to support and facilitate the growth of a diverse and international community of Python programmers.

<a href="https://www.python.org/psf/"><img src="https://wiki.python.org/psf/PSF%20Press%20Kit?action=AttachFile&do=get&target=psf-logo-narrow-256x84-alpha.png" height="55px" alt="Python Software Foundation"></a>

## Show your support

<h3>Star this repo</h3>

Give a ⭐️ if this project helped you!

<h3>Donate to our project</h3>

If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .

<a href="https://openscilab.com/#donation" target="_blank"><img src="https://github.com/openscilab/nava/raw/main/others/donation.png" width="270" alt="Nava Donation"></a>

# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.8] - 2025-12-17
### Added
- `WinMM` engine
### Changed
- `Python 3.14` added to tests
- `run` function in `NavaThread` updated
- `stop` function in `NavaThread` updated
- `README.md` updated
- Test system modified
- `Python 3.6` support dropped
- GitHub actions are limited to the `dev` and `main` branches
## [0.7] - 2024-10-23
### Changed
- `Python 3.13` added to tests
- `engine` parameter added to `play` function
- `engine` parameter added to `NavaThread` class
- `README.md` modified
- Test system modified
- `NavaThread` exception bug fixed
- `__play_win` function renamed to `__play_winsound`
- `__play_mac` function renamed to `__play_afplay`
- `__play_linux` function renamed to `__play_alsa`
## [0.6] - 2024-06-05
### Added
- `play_cli` function
- `SECURITY.md`
### Changed
- `main` function updated
- OSs local checklist added to pull request template
- Test system modified
- `README.md` modified
## [0.5] - 2024-04-03
### Changed
- `loop` parameter added to `play` function
- `NavaThread` class modified
- `README.md` modified
## [0.4] - 2024-02-19
### Added
- `feature_request.yml` template
- `config.yml` for issue template
### Changed
- Bug report template modified
- `NavaThread.stop` method bug fixed
- Test system modified
- `README.md` modified 
## [0.3] - 2024-01-31
### Added
- `NavaThread` class
- `stop` function
- `stop_all` function
### Changed
- `async_mode` parameter added to `play` function
- Test system modified
- `README.md` modified 
- `Python 3.12` added to `linux_test.yml`, `macOS_test.yml` and `windows_test.yml`
## [0.2] - 2023-07-10
### Added
- Logo
- Anaconda package
### Changed
- `quote` decorator bug fixed
- `path_check` decorator bug fixed
- Test system modified
- `README.md` modified 
## [0.1] - 2023-06-10
### Added
- `README.md`
- `__play_win` function
- `__play_linux` function
- `__play_mac` function
- `quote` function
- `path_check` function
- `play` function


[Unreleased]: https://github.com/openscilab/nava/compare/v0.8...dev
[0.8]: https://github.com/openscilab/nava/compare/v0.7...v0.8
[0.7]: https://github.com/openscilab/nava/compare/v0.6...v0.7
[0.6]: https://github.com/openscilab/nava/compare/v0.5...v0.6
[0.5]: https://github.com/openscilab/nava/compare/v0.4...v0.5
[0.4]: https://github.com/openscilab/nava/compare/v0.3...v0.4
[0.3]: https://github.com/openscilab/nava/compare/v0.2...v0.3
[0.2]: https://github.com/openscilab/nava/compare/v0.1...v0.2
[0.1]: https://github.com/openscilab/nava/compare/bd789cc...v0.1