Skip to content

Instantly share code, notes, and snippets.

@akey7
Created June 28, 2020 20:20
Show Gist options
  • Save akey7/c2e21dc11c798e3fd722d42a071baa4a to your computer and use it in GitHub Desktop.
Save akey7/c2e21dc11c798e3fd722d42a071baa4a to your computer and use it in GitHub Desktop.
This creates a sine wave in NumPy and writes it to a wave file.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment