Metadata-Version: 2.4
Name: synthesizer
Version: 0.3.1
Summary: A simple virtual analog synthesizer.
Author-email: Yuma Mihira <info@yurax2.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/yuma-m/synthesizer
Project-URL: Documentation, https://synthesizer.readthedocs.io
Project-URL: Changelog, https://github.com/yuma-m/synthesizer/releases
Keywords: analog,synthesizer
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.22
Requires-Dist: scipy>=1.8
Provides-Extra: audio
Requires-Dist: PyAudio>=0.2.14; extra == "audio"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# Python synthesizer ![Build Status](https://github.com/yuma-m/synthesizer/actions/workflows/build.yml/badge.svg) [![Documentation Status](https://readthedocs.org/projects/synthesizer/badge/?version=latest)](http://synthesizer.readthedocs.io/en/latest/?badge=latest)

- Virtual analog synthesizer. 

## Installation

```bash
$ pip install synthesizer
```

To play sounds with `Player`, install [PyAudio](https://pypi.org/project/PyAudio/) as well.

```bash
$ pip install "synthesizer[audio]"
```

### Install dependencies for PyAudio

#### Ubuntu

```bash
$ apt install portaudio19-dev
```

### macOS

```bash
$ brew install portaudio
```

## Basic usage

### Play 440Hz sine wave

```python
>>> from synthesizer import Player, Synthesizer, Waveform


>>> player = Player()
>>> player.open_stream()
>>> synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False)
# Play A4
>>> player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0))
```

### Play chord

```python
# Play C major
>>> chord = ["C3", "E3", "G3"]
>>> player.play_wave(synthesizer.generate_chord(chord, 3.0))

# You can also specify frequencies to play just intonation
>>> chord = [440.0, 550.0, 660.0]
>>> player.play_wave(synthesizer.generate_chord(chord, 3.0))
```

You can use [PyChord](https://github.com/yuma-m/pychord) to handle chords easily.

```python
>>> from pychord import Chord
>>> chord = Chord("Dm7/G")
>>> player.play_wave(synthesizer.generate_chord(chord.components_with_pitch(root_pitch=3), 3.0))
```

### Attack and release

Each generated wave fades in and out (10 ms by default) to prevent click noise between notes.

```python
>>> synthesizer = Synthesizer(osc1_waveform=Waveform.sine, attack=0.05, release=0.2)
# Disable the envelope
>>> synthesizer = Synthesizer(osc1_waveform=Waveform.sine, attack=0.0, release=0.0)
```

### Specify audio device

```python
>>> player.enumerate_device()
# index: 00, name: "Built-in Microphone", rate: 44100
# index: 01, name: "Built-in Output", rate: 44100
# index: 02, name: "UA-25EX 44.1kHz", rate: 44100
>>> player.open_stream(device_name="UA-25EX")
```

### Write wav file

```python
>>> from synthesizer import Writer
>>> writer = Writer()

>>> chord = ["C4", "E4", "G4"]
>>> wave = synthesizer.generate_chord(chord, 3.0)
>>> writer.write_wave("path/to/your.wav", wave)
```

## Examples

### play_pychord.py

Play chords using [PyChord](https://github.com/yuma-m/pychord).

```bash
pip install pychord>=0.5.0
python example/play_pychord.py A C#m7 DM7 Bm7/E A
```

## Supported OS

- macOS
- Linux

## Supported versions

- Python 3.10 and above

## Author

- [Yuma Mihira](https://yuma.cloud/)

## License

- MIT License

## Links

- PyPI: <https://pypi.python.org/pypi/synthesizer>
- GitHub: <https://github.com/yuma-m/synthesizer>
- Document: <https://synthesizer.readthedocs.io>
