Skip to content

Instantly share code, notes, and snippets.

@pemagrg1
Created March 16, 2020 08:06
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 pemagrg1/395667bf8d6e25cf7feaf6de5d247b30 to your computer and use it in GitHub Desktop.
Save pemagrg1/395667bf8d6e25cf7feaf6de5d247b30 to your computer and use it in GitHub Desktop.
"""
In audio production, a sample rate (or "sampling rate") defines how many times per second a sound is sampled.
Technically speaking, it is the frequency of samples used in a digital recording.
"""
import numpy as np
from scipy.io import wavfile
sampleRate = 100
frequency = 10
audio_length = 1 #second
amplitude = 10
t = np.linspace(0, audio_length, sampleRate * audio_length) # Produces a given 'length' seconds Audio-File
y = amplitude*np.sin(frequency * 2 * np.pi * t) # Has frequency of given 'frequency'
# wavfile.write('Sine.wav', sampleRate, y)
plt.plot(t,y) # plot using pyplot library from matplotlib package
plt.title('Sine wave f='+str(frequency)+' Hz') # plot title
plt.xlabel('Time (s)') # x-axis label
plt.ylabel('Amplitude') # y-axis label
plt.show() # display the figure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment