|
1 | 1 | // This file is part of the CircuitPython project: https://circuitpython.org |
2 | 2 | // |
3 | | -// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries |
4 | 4 | // |
5 | 5 | // SPDX-License-Identifier: MIT |
6 | 6 |
|
|
20 | 20 | //| |
21 | 21 | //| ``AudioWriter`` is the inverse of `audiocore.WaveFile`: rather than being |
22 | 22 | //| an audio *source* played by an `audioio.AudioOut`, it is a *sink* that |
23 | | -//| drives an audio source (a microphone, or an ``audiofilters``/ |
| 23 | +//| drives an audio source (a microphone, ``synthio``, or an ``audiofilters``/ |
24 | 24 | //| ``audiodelays``/``audiofreeverb``/``audiospeed`` effect chain) and writes |
25 | 25 | //| the resulting PCM to a file as a WAV. |
26 | 26 | //| |
27 | 27 | //| Recording runs on a background pump paced to the source's real-time rate, |
28 | | -//| so it does not block and does not require a Python read loop (which is |
29 | | -//| what makes hand-rolled recorders choppy).""" |
| 28 | +//| so it does not block and does not require a Python read loop.""" |
30 | 29 | //| |
31 | 30 | //| def __init__(self, file: typing.BinaryIO, *, buffer_size: int = 32768) -> None: |
32 | 31 | //| """Create an ``AudioWriter`` that writes to ``file``. |
|
42 | 41 | //| The audio format (sample rate, channel count, bit depth) is taken from |
43 | 42 | //| the source at `play()` time, so there are no format arguments here. |
44 | 43 | //| |
45 | | -//| Recording a microphone through an effect chain to SD:: |
| 44 | +//| Recording synthio to SD:: |
46 | 45 | //| |
47 | | -//| import audiowriter, board |
48 | | -//| # ``amp`` is the top of an effect chain pulling from a mic |
49 | | -//| with open("/sd/recording.wav", "wb") as f: |
50 | | -//| writer = audiowriter.AudioWriter(f) |
51 | | -//| writer.play(amp) |
52 | | -//| time.sleep(5) |
| 46 | +//| import time |
| 47 | +//| import synthio |
| 48 | +//| from audiowriter import AudioWriter |
| 49 | +//| import storage |
| 50 | +//| |
| 51 | +//| SAMPLE_RATE = 16000 |
| 52 | +//| OUTPUT_PATH = "/sd/demo_file.wav" |
| 53 | +//| |
| 54 | +//| C_major_scale = [60, 62, 64, 65, 67, 69, 71, 72, 71, 69, 67, 65, 64, 62, 60] |
| 55 | +//| synth = synthio.Synthesizer(sample_rate=SAMPLE_RATE) |
| 56 | +//| |
| 57 | +//| with open(OUTPUT_PATH, "wb") as f: |
| 58 | +//| writer = AudioWriter(f) |
| 59 | +//| writer.play(synth) |
| 60 | +//| for note in C_major_scale: |
| 61 | +//| synth.press(note) |
| 62 | +//| time.sleep(0.1) |
| 63 | +//| synth.release(note) |
| 64 | +//| time.sleep(0.10) |
53 | 65 | //| writer.stop() |
| 66 | +//| print("Done ->", OUTPUT_PATH) |
54 | 67 | //| """ |
55 | 68 | //| ... |
56 | 69 | //| |
|
0 commit comments