When it gets played(I'm not loading everything everytime. I just put
it in the variable once and play with the line;
'AudioFeedback.Play(wx.SOUND_SYNC)' )
for the first time or after a rather long interval, it shows a delay
of (approximately) 0.5 sec.
But, on the same computer, using 'pyAudio', i don't get any delay. it
doesn't matter it's the first-time-play or after long-interval.. it
just plays instantly.
But, pyaudio doesn't support 'non blocking mode' while wxPython gives
the option of 'ASYNC'-mode. (If I understood correctly, wxPython's
SOUND_ASYNC is like non-blocking-mode.)
So.. my question is..
-----------------------------
On the same computer, same setting, and the same application,
I get delay when I use wx.Sound, while I don't get any delay with
pyAudio.
Thus, I assumed that this delay is from wx.Sound's own issue, not with
my own coding or setting of my computer. Do you guys agree with this?
If so, is there any way to improve or fix this delay-issue?
-----------------------------
### Function for playing Feedback Sound
def soundPlay(self):
### Playing
while self.audioFeedbackData != '':
self.stream.write(self.audioFeedbackData)
self.audioFeedbackData = self.wf.readframes(self.chunk)
### rewind & getting ready for the next play
self.wf.rewind()
self.audioFeedbackData = self.wf.readframes(self.chunk)
Your own code shows the likely cause of the perceived delay in wx.Sound. You pyAudio code opens the connection to the audio device and holds it open, so every time you play the sound that connection does not need to be reestablished. On the other hand, wx.Sound reopens the the connection to the audio device each time it is needed, and my guess is that the delay is due to queuing or otherwise dealing with multiple connections to the device within the system. Or perhaps it has to wait for the resource to be released in some other program before it can be acquired in yours, (for example the theme on my linux box plays a sound when buttons are pressed, and the wx.Sound demo starts playing as soon as that button sound is finished.)
I don't know if this is still the case, but as recent as several years ago you could not keep the audio device open on a Linux system without blocking all other applications from using the audio device themselves. And even after multiplexing device drivers came along developers were told that they should not keep an open handle to the audio device when not actively playing audio, so I assume that only opening the device when needed is still considered a best practice.
···
On 4/20/11 12:53 AM, namush wrote:
-----------------------------
On the same computer, same setting, and the same application,
I get delay when I use wx.Sound, while I don't get any delay with
pyAudio.
Thus, I assumed that this delay is from wx.Sound's own issue, not with
my own coding or setting of my computer. Do you guys agree with this?
If so, is there any way to improve or fix this delay-issue?
And.. I guess there won't be an easy & quick solution for this issue.
(I didn't really expect easy solution for this from the beginning.)
I'll try to find another sound-module for this specific application.
Thank you for your answers though.
···
On Apr 20, 9:41 pm, Robin Dunn <ro...@alldunn.com> wrote:
On 4/20/11 12:53 AM, namush wrote:
> -----------------------------
> On the same computer, same setting, and the same application,
> I get delay when I usewx.Sound, while I don't get any delay with
> pyAudio.
> Thus, I assumed that this delay is fromwx.Sound'sown issue, not with
> my own coding or setting of my computer. Do you guys agree with this?
> If so, is there any way to improve or fix this delay-issue?
Your own code shows the likely cause of the perceived delay inwx.Sound.
You pyAudio code opens the connection to the audio device and holds it
open, so every time you play the sound that connection does not need to
be reestablished. On the other hand,wx.Soundreopens the the
connection to the audio device each time it is needed, and my guess is
that the delay is due to queuing or otherwise dealing with multiple
connections to the device within the system. Or perhaps it has to wait
for the resource to be released in some other program before it can be
acquired in yours, (for example the theme on my linux box plays a sound
when buttons are pressed, and thewx.Sounddemo starts playing as soon
as that button sound is finished.)
I don't know if this is still the case, but as recent as several years
ago you could not keep the audio device open on a Linux system without
blocking all other applications from using the audio device themselves.
And even after multiplexing device drivers came along developers were
told that they should not keep an open handle to the audio device when
not actively playing audio, so I assume that only opening the device
when needed is still considered a best practice.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org