Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_audio_generator.py ZZZ an attempt to create beautiful samples of sound
- dir='C://py//audio//samples//'
- ww = 600
- hh = 600
- try:
- from Tkinter import *
- except:
- from tkinter import *
- import random
- import wave
- import math
- import struct
- sample_rate = 44100
- duration = 1 # 1 second of audio
- SAMPLE_LEN = sample_rate * duration
- # -32767 to 32767
- for_amp = 32767
- root = Tk()
- canvas = Canvas(root, width=ww, height=hh, bg='white')
- canvas.pack()
- def save_wave(packed_value):
- sss = str(frequency)+'_'+str(0)
- noise_output = wave.open(dir+sss+'.wav', 'w')
- noise_output.setparams((2, 2, sample_rate, 0, 'NONE', 'not compressed'))
- noise_output.writeframes('\n'.join(packed_value))
- noise_output.close()
- def draw_wave(values):
- canvas.delete(ALL)
- canvas.create_line(values, fill='red')
- canvas.update()
- amplitude = 0.1
- frequency = 20
- # for frequency in range(20,20000,20):
- graph = []
- sound = []
- for bit in range(SAMPLE_LEN*2):
- data = math.sin(bit**amplitude*frequency)
- graph += [(bit,data*(hh-10)/2+hh/2)]
- sound += [struct.pack('h', data*for_amp)]
- draw_wave(graph)
- save_wave(sound)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement