Last active
September 13, 2025 12:31
-
-
Save elderica/cad8b1ee115906cf8cccae2a5d3a9f3d to your computer and use it in GitHub Desktop.
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
import math | |
import array | |
import io | |
import os | |
import os.path as path | |
import wave | |
import winsound | |
wav_hz = 44100 | |
musictime = wav_hz * 5 | |
frq = 440.0 | |
def main(): | |
wave_data = array.array('h') | |
for t in range(musictime): | |
u = 12767 * math.sin(2.0 * math.pi * frq * t / wav_hz) | |
wave_data.append(int(u)) | |
with io.BytesIO() as file: | |
with wave.open(file, 'wb') as wav_file: | |
wav_file.setnchannels(1) | |
wav_file.setsampwidth(2) | |
wav_file.setframerate(wav_hz) | |
wav_file.writeframes(wave_data) | |
winsound.PlaySound(file.getbuffer(), winsound.SND_MEMORY) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment