Skip to content

Instantly share code, notes, and snippets.

@rudrathegreat
Created January 4, 2019 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudrathegreat/8470ad7b8ca6c6067214a3fa4f9980a3 to your computer and use it in GitHub Desktop.
Save rudrathegreat/8470ad7b8ca6c6067214a3fa4f9980a3 to your computer and use it in GitHub Desktop.
Saving Audio Using NumPy and SciPy
import numpy as np
from scipy.io.wavfile import write
sps = 44100 # Samples per Second
freq = 440 # Frequency is Hz
time = 5 # Duration of the audio in seconds
amp = 0.3
# Create the Audio
samples = np.arange(time*sps)
waveform = amp * np.sin(2 * np.pi * samples * freq / sps)
waveform_int = np.int16(waveform)
write('wave.wav', sps, waveform_int)
print('Wavefile has been saved')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment