Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Created July 7, 2020 01:21
Show Gist options
  • Select an option

  • Save KenoLeon/ebd92df2c83ecdd81cfe60fe2e0bda28 to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/ebd92df2c83ecdd81cfe60fe2e0bda28 to your computer and use it in GitHub Desktop.
simple Tone cross platform for Medium article.
# Notes:
# Import and install numpy and simpleaudio
# Volume is louder than winsound
import numpy as np
import simpleaudio as sa
def sound(freq,sec):
frequency = freq
fs = 44100 #samples per second
seconds = sec
t = np.linspace(0, seconds, seconds * fs, False)
note = np.sin(frequency * t * 2 * np.pi)
audio = note * (2**15 - 1) / np.max(np.abs(note))
audio = audio.astype(np.int16)
play_obj = sa.play_buffer(audio, 1, 2, fs)
play_obj.wait_done()
sound(200,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment