Python: NumPy Sine Wave
In this video, I show how to make an audio .wav file from a Python NumPy array.
The code for the tutorial is:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.io.wavfile import write | |
sps = 44100 | |
freq_hz = 440.0 | |
duration_s = 3.0 | |
t_samples = np.arange(sps * duration_s) | |
waveform = np.sin(2 * np.pi * freq_hz * t_samples / sps) | |
waveform *= 0.3 | |
waveform_ints = np.int16(waveform * 32767) | |
write('first_sine.wav', sps, waveform_ints) |