79145593

Date: 2024-10-31 16:46:31
Score: 1
Natty:
Report link

For solve my problem, I made the beginning of the wave from the previous frequency, and and because of this, the very claps that spoiled the sound disappeared. Solution in the code:

# we need to edit only append_sinewave function
audio = []
sample_rate = 44100.0
last_phase = 0  # a variable to save the phase between beeps

def append_sinewave(freq=440.0, duration_milliseconds=500):
    global audio, last_phase
    num_samples = int(duration_milliseconds * (sample_rate / 1000.0))
    
    # adding a signal while continuing the phase
    for x in range(num_samples):
        phase = last_phase + 2 * math.pi * freq * (x / sample_rate)
        sample = math.sin(phase)
        audio.append(sample)
    
    # save the phase so that the next frequency continues the wave
    last_phase += 2 * math.pi * freq * (num_samples / sample_rate)
    last_phase %= 2 * math.pi  # normalizing
    return

Thanks to OysterShucker for idea

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: kotek