Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_audio_generator2.py ZZZ not near what I hope for, but... will most likely do from data training
- 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.12
- for frequency in range(1,20000):
- graph = []
- sound = []
- for bit in range(SAMPLE_LEN*2):
- amp = math.sin((bit+16)**amplitude*frequency)
- b = bit*0.1
- data = (amp+math.sin(b*frequency)+math.sin(b*(frequency+2)))/3
- graph += [(bit,data*(hh-10/2-bit)+hh/2)]
- sound += [struct.pack('h', data*100)]
- draw_wave(graph)
- save_wave(sound)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement