Too high latency while trying to manipulate sound arrays using sounddevice in python
<p>Few days ago, I have installed <a href="http://python-sounddevice.readthedocs.io/en/0.3.5/" rel="nofollow">a sounddevice</a> library in Python 2.7.5. I'm trying to make a sound array and add some effects to it immediately after I push a key on my MIDI controller. But I get a huge delay of 0.1 to 0.2 second which makes my code useless:</p>

<pre><code>import numpy as np
import sounddevice as sd
import time
import math

#we're making a sound array with a 5 seconds length noisy sound and playing it:
duration=5
framerate = 44100
array=0.02*np.random.uniform(-1, 1, framerate*duration)
sd.play(array, framerate)

t=time.time()
while(True):
    signal=raw_input("push ENTER to hear a beep")
    start_iter=int(framerate*(time.time()-t))
    end_iter=min(start_iter+framerate/4, len(array))

    #we're trying to change our data array and play a beep signal of 0.25 second after each ENTER press instantly
    for i in range(start_iter, end_iter):
        array[i]=0.05*math.sin(440*2*math.pi*i/44100.)
    if end_iter==len(array): break #safe exit of a process after 5 seconds has passed
</code></pre>

<p>To keep it simple, my sound array is just a noisy sound and my effect consists of a 440Hz beep. I used raw_input() here (type "input()" in Python 3.x) instead of MIDI inputs which could be possible using Pygame library. My code works but each time we press ENTER we will hear a short delay before beep signal.
Is it possible to eliminate it? If not, any other libraries allowing to play a sound stream with no delays live?</p>