Created
July 7, 2020 01:21
-
-
Save KenoLeon/ebd92df2c83ecdd81cfe60fe2e0bda28 to your computer and use it in GitHub Desktop.
simple Tone cross platform for Medium article.
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
| # 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