Dec-16-2020, 06:15 PM
hello,
I have a python project where I should use this fonction to make musics.
So how should I call my function sound to execute the two at the same time ?
I have a python project where I should use this fonction to make musics.
from simpleaudio import * import numpy as np def sound(freq, duration): sample_rate = 44100 t = np.linspace(0, duration, int(duration * sample_rate), False) tone = np.sin(freq * t * 2 * np.pi) tone *= 8388607 / np.max(np.abs(tone)) tone = tone.astype(np.int32) i = 0 byte_array = [] for b in tone.tobytes(): if i % 4 != 3: byte_array.append(b) i += 1 audio = bytearray(byte_array) play_obj = play_buffer(audio, 1, 3, sample_rate) play_obj.wait_done()I want to integrate this function in a Tkinter window to play music while displaying notes on the screen. I know how to display the note but my function sound block my Tkinter window.
So how should I call my function sound to execute the two at the same time ?